Intercept received messages and queue them
- Exposes behavior under QUEUE_MESSAGE_ENABLED flag that is turned off in production. - Delays messages to allow for reordering of latecoming messages up to 500ms
This commit is contained in:
parent
fa61ef8e1d
commit
751998e980
1
.env
1
.env
|
@ -7,3 +7,4 @@ OFFLINE_INBOX_ENABLED=1
|
|||
LOG_LEVEL=debug
|
||||
LOG_LEVEL_STATUS_GO=info
|
||||
JSC_ENABLED=1
|
||||
QUEUE_MESSAGE_ENABLED=1
|
|
@ -7,3 +7,4 @@ OFFLINE_INBOX_ENABLED=1
|
|||
LOG_LEVEL=debug
|
||||
LOG_LEVEL_STATUS_GO=info
|
||||
JSC_ENABLED=0
|
||||
QUEUE_MESSAGE_ENABLED=1
|
||||
|
|
|
@ -7,3 +7,4 @@ OFFLINE_INBOX_ENABLED=0
|
|||
LOG_LEVEL=info
|
||||
LOG_LEVEL_STATUS_GO=
|
||||
JSC_ENABLED=0
|
||||
QUEUE_MESSAGE_ENABLED=0
|
|
@ -20,6 +20,7 @@
|
|||
status-im.chat.events.commands
|
||||
status-im.chat.events.requests
|
||||
status-im.chat.events.animation
|
||||
status-im.chat.events.queue-message
|
||||
status-im.chat.events.receive-message
|
||||
status-im.chat.events.sign-up
|
||||
status-im.chat.events.console
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
(ns status-im.chat.events.queue-message
|
||||
(:require-macros [cljs.core.async.macros :as async-macros])
|
||||
(:require [cljs.core.async :as async]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.pre-receiver :as pre-receiver]
|
||||
[status-im.utils.handlers :as handlers]))
|
||||
|
||||
;; We queue messaged before receiving them to allow lagging messages to catch up.
|
||||
;; This ensures proper ordering from a user's POV the vast majority of the time.
|
||||
|
||||
;; XXX(oskarth): Hacky def, consider better encapsulation
|
||||
(when config/queue-message-enabled?
|
||||
(def in-ch (pre-receiver/start!
|
||||
{:delay-ms 500
|
||||
:reorder? true
|
||||
:add-fn #(re-frame/dispatch [:chat-received-message/add %])})))
|
||||
|
||||
;; NOTE(oskarth): in-ch is assumed to exist
|
||||
(re-frame/reg-fx
|
||||
::queue-message
|
||||
(fn [message]
|
||||
(async/put! in-ch message)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:pre-received-message
|
||||
(fn [_ [_ message]]
|
||||
(if config/queue-message-enabled?
|
||||
{::queue-message message}
|
||||
{:dispatch [:chat-received-message/add message]})))
|
|
@ -316,7 +316,7 @@
|
|||
route-fx (case type
|
||||
(:message
|
||||
:group-message
|
||||
:public-group-message) {:dispatch [:chat-received-message/add (transform-protocol-message message)]}
|
||||
:public-group-message) {:dispatch [:pre-received-message (transform-protocol-message message)]}
|
||||
:pending (cond-> {::pending-messages-save message}
|
||||
chat-message
|
||||
(assoc :dispatch
|
||||
|
|
|
@ -30,3 +30,4 @@
|
|||
keyword))
|
||||
|
||||
(def jsc-enabled? (enabled? (get-config :JSC_ENABLED 0)))
|
||||
(def queue-message-enabled? (enabled? (get-config :QUEUE_MESSAGE_ENABLED 0)))
|
||||
|
|
Loading…
Reference in New Issue