Fix clearing unread counter

This commit is contained in:
janherich 2018-07-04 17:07:31 +02:00
parent a7a7543c53
commit be0143a575
No known key found for this signature in database
GPG Key ID: C23B473AFBE94D13
3 changed files with 21 additions and 11 deletions

View File

@ -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

View File

@ -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

View File

@ -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])))))