[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")))))) (aget msg "message-id"))))))
@chat-id->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 (re-frame/reg-cofx
:data-store/unviewed-messages :data-store/get-unviewed-messages
(fn [{:keys [db] :as cofx} _] (fn [cofx _]
(assoc cofx (assoc cofx
:stored-unviewed-messages :get-stored-unviewed-messages
(into {} get-unviewed-messages)))
(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)))))))
(defn- prepare-content [content] (defn- prepare-content [content]
(if (string? content) (if (string? content)

View File

@ -68,7 +68,7 @@
(re-frame/inject-cofx :data-store/all-chats) (re-frame/inject-cofx :data-store/all-chats)
(re-frame/inject-cofx :data-store/get-messages) (re-frame/inject-cofx :data-store/get-messages)
(re-frame/inject-cofx :data-store/get-user-statuses) (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/message-ids)
(re-frame/inject-cofx :data-store/get-unanswered-requests) (re-frame/inject-cofx :data-store/get-unanswered-requests)
(re-frame/inject-cofx :data-store/get-local-storage-data) (re-frame/inject-cofx :data-store/get-local-storage-data)

View File

@ -46,12 +46,13 @@
stored-unanswered-requests stored-unanswered-requests
get-stored-messages get-stored-messages
get-stored-user-statuses get-stored-user-statuses
stored-unviewed-messages get-stored-unviewed-messages
stored-message-ids] :as cofx}] stored-message-ids] :as cofx}]
(let [chat->message-id->request (reduce (fn [acc {:keys [chat-id message-id] :as request}] (let [chat->message-id->request (reduce (fn [acc {:keys [chat-id message-id] :as request}]
(assoc-in acc [chat-id message-id] request)) (assoc-in acc [chat-id message-id] request))
{} {}
stored-unanswered-requests) stored-unanswered-requests)
stored-unviewed-messages (get-stored-unviewed-messages (:current-public-key db))
chats (reduce (fn [acc {:keys [chat-id] :as chat}] chats (reduce (fn [acc {:keys [chat-id] :as chat}]
(let [chat-messages (index-messages (get-stored-messages chat-id)) (let [chat-messages (index-messages (get-stored-messages chat-id))
message-ids (keys chat-messages) message-ids (keys chat-messages)