|
12 | 12 |
|
13 | 13 | (fx/defn handle-activities [{:keys [db]} activities]
|
14 | 14 | (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)))))) |
34 | 43 | {:unread-count (get db :activity.center/notifications-count 0)
|
35 | 44 | :notifications (into [] (get-in db [:activity.center/notifications :notifications]))}
|
36 | 45 | activities)]
|
|
0 commit comments