Fix disappearing of the last notification when paired

This commit is contained in:
Roman Volosovskyi 2022-08-15 13:01:30 +02:00
parent 959df25c02
commit 24ef84b890
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
1 changed files with 27 additions and 18 deletions

View File

@ -12,25 +12,34 @@
(fx/defn handle-activities [{:keys [db]} activities]
(let [{:keys [unread-count notifications]}
(reduce (fn [acc {:keys [read dismissed accepted] :as notification}]
(let [index-existing (->> (map-indexed vector (:notifications acc))
(filter (fn [[idx {:keys [id]}]] (= id (:id notification))))
first
first)]
(as-> acc a
(if read
(update a :unread-count dec)
(update a :unread-count inc))
(reduce (fn [acc {:keys [read dismissed accepted chat-id] :as notification}]
(if (= "" chat-id)
;; TODO(rasom): sometimes messages come with empty `chat-id`s
;; (specifically it happens on `SyncActivityCenterRead` message).
;; In result, if notification is received with notification center
;; screen opened, and there is another paired device online, the
;; last notification disappear from the screen and is shown only
;; after reopening. It likely makes sense to fix it on status-go
;; side, but I got lost a bit.
acc
(let [index-existing (->> (map-indexed vector (:notifications acc))
(filter (fn [[idx {:keys [id]}]] (= id (:id notification))))
first
first)]
(as-> acc a
(if read
(update a :unread-count dec)
(update a :unread-count inc))
(if index-existing
(if (or dismissed accepted)
;; Remove at specific location
(assoc a :notifications
(into (subvec (:notifications a) 0 index-existing) (subvec (:notifications a) (inc index-existing))))
;; Replace element
(do
(assoc-in a [:notifications index-existing] notification)))
(update a :notifications conj notification)))))
(if index-existing
(if (or dismissed accepted)
;; Remove at specific location
(assoc a :notifications
(into (subvec (:notifications a) 0 index-existing) (subvec (:notifications a) (inc index-existing))))
;; Replace element
(do
(assoc-in a [:notifications index-existing] notification)))
(update a :notifications conj notification))))))
{:unread-count (get db :activity.center/notifications-count 0)
:notifications (into [] (get-in db [:activity.center/notifications :notifications]))}
activities)]