[fix 5738] unread counter disappears after app restart

`get-unviewed-messages` cofx was using the `current-public-key`
field from app-db
since it is not set at the point cofx are computed during the init
phase this field is nil and therefore no unread messages were found

the fix changes the cofx so that it returns a function as it is
already done for many cofx that needs parameters that are not
known at the time cofx are computed.

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Eric Dvorsak 2018-09-04 12:38:00 +02:00 committed by Igor Mandrigin
parent 495f513de9
commit 6d84795b2a
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
3 changed files with 20 additions and 15 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)