diff --git a/src/status_im/chat/events.cljs b/src/status_im/chat/events.cljs index 3d963d14d0..b94fa08456 100644 --- a/src/status_im/chat/events.cljs +++ b/src/status_im/chat/events.cljs @@ -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/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")})))))))) diff --git a/src/status_im/data_store/realm/schemas/account/v19/user_status.cljs b/src/status_im/data_store/realm/schemas/account/v19/user_status.cljs index 6d1f99ac66..e0ba8fef4d 100644 --- a/src/status_im/data_store/realm/schemas/account/v19/user_status.cljs +++ b/src/status_im/data_store/realm/schemas/account/v19/user_status.cljs @@ -1,7 +1,12 @@ (ns status-im.data-store.realm.schemas.account.v19.user-status) -(def schema {:name :user-status - :properties {:message-id :string +(def schema {:name :user-status + :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}}) diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index d7fe485137..fa3df5a394 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -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}}