diff --git a/src/status_im/data_store/messages.cljs b/src/status_im/data_store/messages.cljs index 0fed121f32..eea8ab758e 100644 --- a/src/status_im/data_store/messages.cljs +++ b/src/status_im/data_store/messages.cljs @@ -55,21 +55,25 @@ (aget msg "message-id")))))) @chat-id->message-id)))) +(defn- get-unviewed-messages + [public-key] + (into {} + (map (fn [[chat-id user-statuses]] + [chat-id (into #{} (map :message-id) user-statuses)])) + (group-by :chat-id + (-> @core/account-realm + (core/get-by-fields + :user-status + :and {:whisper-identity public-key + :status "received"}) + (core/all-clj :user-status))))) + (re-frame/reg-cofx - :data-store/unviewed-messages - (fn [{:keys [db] :as cofx} _] + :data-store/get-unviewed-messages + (fn [cofx _] (assoc cofx - :stored-unviewed-messages - (into {} - (map (fn [[chat-id user-statuses]] - [chat-id (into #{} (map :message-id) user-statuses)])) - (group-by :chat-id - (-> @core/account-realm - (core/get-by-fields - :user-status - :and {:whisper-identity (:current-public-key db) - :status "received"}) - (core/all-clj :user-status))))))) + :get-stored-unviewed-messages + get-unviewed-messages))) (defn- prepare-content [content] (if (string? content) diff --git a/src/status_im/init/events.cljs b/src/status_im/init/events.cljs index 8406b833dd..3241a7eb81 100644 --- a/src/status_im/init/events.cljs +++ b/src/status_im/init/events.cljs @@ -68,7 +68,7 @@ (re-frame/inject-cofx :data-store/all-chats) (re-frame/inject-cofx :data-store/get-messages) (re-frame/inject-cofx :data-store/get-user-statuses) - (re-frame/inject-cofx :data-store/unviewed-messages) + (re-frame/inject-cofx :data-store/get-unviewed-messages) (re-frame/inject-cofx :data-store/message-ids) (re-frame/inject-cofx :data-store/get-unanswered-requests) (re-frame/inject-cofx :data-store/get-local-storage-data) diff --git a/src/status_im/models/chat.cljs b/src/status_im/models/chat.cljs index 515b4d0bd2..79e41bb4be 100644 --- a/src/status_im/models/chat.cljs +++ b/src/status_im/models/chat.cljs @@ -46,12 +46,13 @@ stored-unanswered-requests get-stored-messages get-stored-user-statuses - stored-unviewed-messages + get-stored-unviewed-messages stored-message-ids] :as cofx}] (let [chat->message-id->request (reduce (fn [acc {:keys [chat-id message-id] :as request}] (assoc-in acc [chat-id message-id] request)) {} stored-unanswered-requests) + stored-unviewed-messages (get-stored-unviewed-messages (:current-public-key db)) chats (reduce (fn [acc {:keys [chat-id] :as chat}] (let [chat-messages (index-messages (get-stored-messages chat-id)) message-ids (keys chat-messages)