Faster msg status updates
This commit is contained in:
parent
1ec7053aee
commit
201484f37f
|
@ -1,5 +1,7 @@
|
|||
(ns status-im.chat.events
|
||||
(:require [re-frame.core :as re-frame]
|
||||
(:require-macros [cljs.core.async.macros :as async])
|
||||
(:require [cljs.core.async :as async]
|
||||
[re-frame.core :as re-frame]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.gfycat.core :as gfycat]
|
||||
|
@ -54,13 +56,19 @@
|
|||
(fn [cofx _]
|
||||
(assoc cofx :get-stored-chat chats-store/get-by-id)))
|
||||
|
||||
|
||||
;;;; Effects
|
||||
|
||||
(def ^:private update-message-queue (async/chan 100))
|
||||
|
||||
(async/go-loop [message (async/<! update-message-queue)]
|
||||
(when message
|
||||
(messages-store/update-message message)
|
||||
(recur (async/<! update-message-queue))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:update-message
|
||||
(fn [message]
|
||||
(messages-store/update-message message)))
|
||||
(async/put! update-message-queue message)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:save-message
|
||||
|
|
|
@ -64,7 +64,8 @@
|
|||
(utils/update-if-present message
|
||||
:user-statuses
|
||||
(partial map (fn [[whisper-identity status]]
|
||||
{:whisper-identity whisper-identity
|
||||
{:status-id (str message-id "-" whisper-identity)
|
||||
:whisper-identity whisper-identity
|
||||
:status status
|
||||
:chat-id chat-id
|
||||
:message-id message-id}))))
|
||||
|
|
|
@ -112,9 +112,11 @@
|
|||
statuses (aget msg "user-statuses")]
|
||||
(when statuses
|
||||
(.map statuses (fn [status _ _]
|
||||
(aset status "status-id" (str message-id "-" from))
|
||||
(aset status "message-id" message-id)
|
||||
(aset status "chat-id" chat-id)))
|
||||
(.push statuses (clj->js {"message-id" message-id
|
||||
(.push statuses (clj->js {"status-id" (str message-id "-anonymous")
|
||||
"message-id" message-id
|
||||
"chat-id" chat-id
|
||||
"status" (or msg-status "received")
|
||||
"whisper-identity" (or from "anonymous")}))))))))
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
(ns status-im.data-store.realm.schemas.account.v19.user-status)
|
||||
|
||||
(def schema {:name :user-status
|
||||
:properties {:message-id :string
|
||||
:primaryKey :status-id
|
||||
:properties {;; Unfortunately, realm doesn't support composite primary keys,
|
||||
;; so we have to keep separate `:status-id` property, which is just
|
||||
;; `:message-id`-`:whisper-identity` concatenated
|
||||
:status-id :string
|
||||
:message-id :string
|
||||
:chat-id :string
|
||||
:whisper-identity :string
|
||||
:status :string}})
|
||||
|
|
|
@ -61,13 +61,6 @@
|
|||
(and (chats/is-active? group-id)
|
||||
(> timestamp (chats/get-property group-id :timestamp)))))))
|
||||
|
||||
(re-frame/reg-cofx
|
||||
::chats-is-active?
|
||||
(fn [coeffects _]
|
||||
(let [[{{:keys [group-id]} :payload from :from}] (:event coeffects)]
|
||||
(assoc coeffects :chats-is-active?
|
||||
(chats/is-active? (or group-id from))))))
|
||||
|
||||
(re-frame/reg-cofx
|
||||
::has-contact?
|
||||
(fn [coeffects _]
|
||||
|
@ -347,16 +340,17 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:update-message-status
|
||||
[re-frame/trim-v
|
||||
(re-frame/inject-cofx :get-stored-message)
|
||||
(re-frame/inject-cofx ::chats-is-active?)]
|
||||
(fn [{:keys [db chats-is-active? get-stored-message]} [{:keys [from sent-from payload]} status]]
|
||||
[re-frame/trim-v (re-frame/inject-cofx :get-stored-message)]
|
||||
(fn [{:keys [db get-stored-message]} [{:keys [from sent-from payload]} status]]
|
||||
(let [message-identifier (get-message-id payload)
|
||||
message-db-path [:chats (or (:group-id payload) from) :messages message-identifier]
|
||||
chat-identifier (or (:group-id payload) from)
|
||||
message-db-path [:chats chat-identifier :messages message-identifier]
|
||||
from-id (or sent-from from)
|
||||
message (get-stored-message message-identifier)]
|
||||
;; proceed with updating status if chat is active, and message was not already seen
|
||||
(when (and chats-is-active? (not (chat.utils/message-seen-by? message from-id)))
|
||||
;; proceed with updating status if chat is in db, status is not the same and message was not already seen
|
||||
(when (and (get-in db [:chats chat-identifier])
|
||||
(not= status (get-in message [:user-statuses from-id]))
|
||||
(not (chat.utils/message-seen-by? message from-id)))
|
||||
(let [statuses (assoc (:user-statuses message) from-id status)]
|
||||
(cond-> {:update-message {:message-id message-identifier
|
||||
:user-statuses statuses}}
|
||||
|
|
Loading…
Reference in New Issue