[slow sign in] faster get-unviewed-messages

This commit is contained in:
Roman Volosovskyi 2018-11-20 18:13:21 +02:00
parent 605f8d2590
commit b792ab5cf3
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE

View File

@ -82,16 +82,16 @@
(defn- get-unviewed-messages (defn- get-unviewed-messages
[public-key] [public-key]
(into {} (-> @core/account-realm
(map (fn [[chat-id user-statuses]] (core/get-by-fields
[chat-id (into #{} (map :message-id) user-statuses)])) :user-status
(group-by :chat-id :and {:public-key public-key
(-> @core/account-realm :status "received"})
(core/get-by-fields (.reduce (fn [acc msg _ _]
:user-status (let [chat-id (aget msg "chat-id")
:and {:public-key public-key message-id (aget msg "message-id")]
:status "received"}) (update acc chat-id (fnil conj #{}) message-id)))
(core/all-clj :user-status))))) {})))
(re-frame/reg-cofx (re-frame/reg-cofx
:data-store/get-unviewed-messages :data-store/get-unviewed-messages