Skip to content

Commit 24ef84b

Browse files
committed
Fix disappearing of the last notification when paired
1 parent 959df25 commit 24ef84b

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/status_im/notifications_center/core.cljs

+28-19
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,34 @@
1212

1313
(fx/defn handle-activities [{:keys [db]} activities]
1414
(let [{:keys [unread-count notifications]}
15-
(reduce (fn [acc {:keys [read dismissed accepted] :as notification}]
16-
(let [index-existing (->> (map-indexed vector (:notifications acc))
17-
(filter (fn [[idx {:keys [id]}]] (= id (:id notification))))
18-
first
19-
first)]
20-
(as-> acc a
21-
(if read
22-
(update a :unread-count dec)
23-
(update a :unread-count inc))
24-
25-
(if index-existing
26-
(if (or dismissed accepted)
27-
;; Remove at specific location
28-
(assoc a :notifications
29-
(into (subvec (:notifications a) 0 index-existing) (subvec (:notifications a) (inc index-existing))))
30-
;; Replace element
31-
(do
32-
(assoc-in a [:notifications index-existing] notification)))
33-
(update a :notifications conj notification)))))
15+
(reduce (fn [acc {:keys [read dismissed accepted chat-id] :as notification}]
16+
(if (= "" chat-id)
17+
;; TODO(rasom): sometimes messages come with empty `chat-id`s
18+
;; (specifically it happens on `SyncActivityCenterRead` message).
19+
;; In result, if notification is received with notification center
20+
;; screen opened, and there is another paired device online, the
21+
;; last notification disappear from the screen and is shown only
22+
;; after reopening. It likely makes sense to fix it on status-go
23+
;; side, but I got lost a bit.
24+
acc
25+
(let [index-existing (->> (map-indexed vector (:notifications acc))
26+
(filter (fn [[idx {:keys [id]}]] (= id (:id notification))))
27+
first
28+
first)]
29+
(as-> acc a
30+
(if read
31+
(update a :unread-count dec)
32+
(update a :unread-count inc))
33+
34+
(if index-existing
35+
(if (or dismissed accepted)
36+
;; Remove at specific location
37+
(assoc a :notifications
38+
(into (subvec (:notifications a) 0 index-existing) (subvec (:notifications a) (inc index-existing))))
39+
;; Replace element
40+
(do
41+
(assoc-in a [:notifications index-existing] notification)))
42+
(update a :notifications conj notification))))))
3443
{:unread-count (get db :activity.center/notifications-count 0)
3544
:notifications (into [] (get-in db [:activity.center/notifications :notifications]))}
3645
activities)]

0 commit comments

Comments
 (0)