fix: Marking AC notification as read does not affect correspondent message in chat (#18058)

This commit is contained in:
frank 2023-12-07 10:16:25 +08:00 committed by GitHub
parent 198a4d74a5
commit aa89ebdb93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 14 deletions

View File

@ -45,6 +45,7 @@
{:db (update-in db [:chats chat-id] merge chat)}))
(rf/defn load-chat
{:events [:chats-list/load-chat]}
[_ chat-id]
{:json-rpc/call [{:method "wakuext_chat"
:params [chat-id]

View File

@ -122,10 +122,13 @@
:on-error [:activity-center/process-notification-failure notification-id
:notification/mark-as-read]}]}))
(rf/defn mark-as-read-success
{:events [:activity-center.notifications/mark-as-read-success]}
[cofx notification]
(notifications-reconcile cofx [(assoc notification :read true)]))
(defn mark-as-read-success
[_ [{:keys [chat-id] :as notification}]]
{:fx [(when chat-id
[:dispatch [:chats-list/load-chat chat-id]])
[:dispatch [:activity-center.notifications/reconcile [(assoc notification :read true)]]]]})
(rf/reg-event-fx :activity-center.notifications/mark-as-read-success mark-as-read-success)
(rf/defn mark-as-unread
{:events [:activity-center.notifications/mark-as-unread]}

View File

@ -63,16 +63,12 @@
(events/mark-as-read cofx (:id notif)))))))
(deftest mark-as-read-success-test
(let [f-args (atom [])
cofx {:db {}}
notif {:id "0x1" :read false :type types/one-to-one-chat}]
(with-redefs [events/notifications-reconcile
(fn [& args]
(reset! f-args args)
:result)]
(is (= :result (events/mark-as-read-success cofx notif)))
(is (match? [cofx [(assoc notif :read true)]]
@f-args)))))
(let [cofx {:db {}}
notif {:id "0x1" :read false :type types/one-to-one-chat :chat-id "chat-id"}
expected-fx {:fx [[:dispatch [:chats-list/load-chat "chat-id"]]
[:dispatch
[:activity-center.notifications/reconcile [(assoc notif :read true)]]]]}]
(is (match? expected-fx (events/mark-as-read-success cofx [notif])))))
(deftest mark-as-unread-test
(testing "does nothing if the notification ID cannot be found in the app db"