Fix clearing unread counter
This commit is contained in:
parent
a7a7543c53
commit
be0143a575
|
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fixed mailservers connectivity issue
|
- Fixed mailservers connectivity issue
|
||||||
|
- Clear chat action correctly clear the unread messages counter
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Downgraded React Native to 0.53.3 for improved performance and decreased battery consumption
|
- Downgraded React Native to 0.53.3 for improved performance and decreased battery consumption
|
||||||
|
|
|
@ -85,13 +85,14 @@
|
||||||
:clock-value)
|
:clock-value)
|
||||||
deleted-at-clock-value
|
deleted-at-clock-value
|
||||||
(utils.clocks/send 0))]
|
(utils.clocks/send 0))]
|
||||||
;; Necessary until we adjust merge-fx to cater for :txs
|
{:db (update-in db [:chats chat-id] merge
|
||||||
(-> (select-keys cofx [:data-store/tx :db])
|
{:messages {}
|
||||||
(assoc-in [:db :chats chat-id :messages] {})
|
:message-groups {}
|
||||||
(assoc-in [:db :chats chat-id :message-groups] {})
|
:unviewed-messages #{}
|
||||||
(assoc-in [:db :chats chat-id :deleted-at-clock-value] last-message-clock-value)
|
:not-loaded-message-ids #{}
|
||||||
(update :data-store/tx concat [(chats-store/clear-history-tx chat-id last-message-clock-value)
|
:deleted-at-clock-value last-message-clock-value})
|
||||||
(messages-store/delete-messages-tx chat-id)]))))
|
: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}]
|
(defn- remove-transport [chat-id {:keys [db] :as cofx}]
|
||||||
;; if this is private group chat, we have to broadcast leave and unsubscribe after that
|
;; if this is private group chat, we have to broadcast leave and unsubscribe after that
|
||||||
|
|
|
@ -104,16 +104,24 @@
|
||||||
|
|
||||||
(deftest clear-history-test
|
(deftest clear-history-test
|
||||||
(let [chat-id "1"
|
(let [chat-id "1"
|
||||||
cofx {:db {:chats {chat-id {:message-groups {:something "a"}
|
cofx {:db {:chats {chat-id {:message-groups {:something "a"}
|
||||||
:messages {"1" {:clock-value 1}
|
:messages {"1" {:clock-value 1}
|
||||||
"2" {:clock-value 10}
|
"2" {:clock-value 10}
|
||||||
"3" {:clock-value 2}}}}}}]
|
"3" {:clock-value 2}}
|
||||||
|
:unviewed-messages #{"3"}
|
||||||
|
:not-loaded-message-ids #{"2" "3"}}}}}]
|
||||||
(testing "it deletes all the messages"
|
(testing "it deletes all the messages"
|
||||||
(let [actual (chat/clear-history chat-id cofx)]
|
(let [actual (chat/clear-history chat-id cofx)]
|
||||||
(is (= {} (get-in actual [:db :chats chat-id :messages])))))
|
(is (= {} (get-in actual [:db :chats chat-id :messages])))))
|
||||||
(testing "it deletes all the message groups"
|
(testing "it deletes all the message groups"
|
||||||
(let [actual (chat/clear-history chat-id cofx)]
|
(let [actual (chat/clear-history chat-id cofx)]
|
||||||
(is (= {} (get-in actual [:db :chats chat-id :message-groups])))))
|
(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"
|
(testing "it sets a deleted-at-clock-value equal to the last message clock-value"
|
||||||
(let [actual (chat/clear-history chat-id cofx)]
|
(let [actual (chat/clear-history chat-id cofx)]
|
||||||
(is (= 10 (get-in actual [:db :chats chat-id :deleted-at-clock-value])))))
|
(is (= 10 (get-in actual [:db :chats chat-id :deleted-at-clock-value])))))
|
||||||
|
|
Loading…
Reference in New Issue