From be0143a5755e2d72bd9665474d9e4493fb9f3233 Mon Sep 17 00:00:00 2001 From: janherich Date: Wed, 4 Jul 2018 17:07:31 +0200 Subject: [PATCH] Fix clearing unread counter --- CHANGELOG.md | 1 + src/status_im/chat/models.cljs | 15 ++++++++------- test/cljs/status_im/test/chat/models.cljs | 16 ++++++++++++---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c85a49954..d5d98b2c28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed mailservers connectivity issue +- Clear chat action correctly clear the unread messages counter ### Changed - Downgraded React Native to 0.53.3 for improved performance and decreased battery consumption diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index 6166fbe8fc..c2b0357f2f 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -85,13 +85,14 @@ :clock-value) deleted-at-clock-value (utils.clocks/send 0))] - ;; Necessary until we adjust merge-fx to cater for :txs - (-> (select-keys cofx [:data-store/tx :db]) - (assoc-in [:db :chats chat-id :messages] {}) - (assoc-in [:db :chats chat-id :message-groups] {}) - (assoc-in [:db :chats chat-id :deleted-at-clock-value] last-message-clock-value) - (update :data-store/tx concat [(chats-store/clear-history-tx chat-id last-message-clock-value) - (messages-store/delete-messages-tx chat-id)])))) + {:db (update-in db [:chats chat-id] merge + {:messages {} + :message-groups {} + :unviewed-messages #{} + :not-loaded-message-ids #{} + :deleted-at-clock-value last-message-clock-value}) + :data-store/tx [(chats-store/clear-history-tx chat-id last-message-clock-value) + (messages-store/delete-messages-tx chat-id)]})) (defn- remove-transport [chat-id {:keys [db] :as cofx}] ;; if this is private group chat, we have to broadcast leave and unsubscribe after that diff --git a/test/cljs/status_im/test/chat/models.cljs b/test/cljs/status_im/test/chat/models.cljs index 84ddb03267..c6f2451dd3 100644 --- a/test/cljs/status_im/test/chat/models.cljs +++ b/test/cljs/status_im/test/chat/models.cljs @@ -104,16 +104,24 @@ (deftest clear-history-test (let [chat-id "1" - cofx {:db {:chats {chat-id {:message-groups {:something "a"} - :messages {"1" {:clock-value 1} - "2" {:clock-value 10} - "3" {:clock-value 2}}}}}}] + cofx {:db {:chats {chat-id {:message-groups {:something "a"} + :messages {"1" {:clock-value 1} + "2" {:clock-value 10} + "3" {:clock-value 2}} + :unviewed-messages #{"3"} + :not-loaded-message-ids #{"2" "3"}}}}}] (testing "it deletes all the messages" (let [actual (chat/clear-history chat-id cofx)] (is (= {} (get-in actual [:db :chats chat-id :messages]))))) (testing "it deletes all the message groups" (let [actual (chat/clear-history chat-id cofx)] (is (= {} (get-in actual [:db :chats chat-id :message-groups]))))) + (testing "it deletes unviewed messages set" + (let [actual (chat/clear-history chat-id cofx)] + (is (= #{} (get-in actual [:db :chats chat-id :unviewed-messages]))))) + (testing "it deletes not loaded message ids set" + (let [actual (chat/clear-history chat-id cofx)] + (is (= #{} (get-in actual [:db :chats chat-id :not-loaded-message-ids]))))) (testing "it sets a deleted-at-clock-value equal to the last message clock-value" (let [actual (chat/clear-history chat-id cofx)] (is (= 10 (get-in actual [:db :chats chat-id :deleted-at-clock-value])))))