diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index 17947b352d0c..1e860088f9e3 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -46,7 +46,8 @@ (community-chat? (get-chat cofx chat-id)))) (defn active-chat? [cofx chat-id] - (not (nil? (get-chat cofx chat-id)))) + (let [chat (get-chat cofx chat-id)] + (not (nil? chat)))) (defn foreground-chat? [{{:keys [current-chat-id view-id]} :db} chat-id] @@ -102,6 +103,13 @@ (fn [val] (and (not (get-in db [:chats (:chat-id val)])) (:public? val)))) +(fx/defn leave-removed-chat + [{{:keys [view-id current-chat-id chats]} :db + :as cofx}] + (when (and (= view-id :chat) + (not (contains? chats current-chat-id))) + (navigation/navigate-back cofx))) + (fx/defn ensure-chats "Add chats to db and update" [{:keys [db] :as cofx} chats] @@ -118,11 +126,14 @@ :chats-home-list #{} :removed-chats #{}} (map (map-chats cofx) chats))] - {:db (-> db - (update :chats merge all-chats) - (update :chats-home-list set/union chats-home-list) - (update :chats #(apply dissoc % removed-chats)) - (update :chats-home-list set/difference removed-chats))})) + (fx/merge + cofx + {:db (-> db + (update :chats merge all-chats) + (update :chats-home-list set/union chats-home-list) + (update :chats #(apply dissoc % removed-chats)) + (update :chats-home-list set/difference removed-chats))} + leave-removed-chat))) (fx/defn clear-history "Clears history of the particular chat" @@ -137,11 +148,14 @@ {:db (-> db (assoc-in [:messages chat-id] {}) (update-in [:message-lists] dissoc chat-id) - (update-in [:chats chat-id] merge - {:last-message nil - :unviewed-messages-count 0 - :unviewed-mentions-count 0 - :deleted-at-clock-value last-message-clock-value}))})) + (update :chats (fn [chats] + (if (contains? chats chat-id) + (update chats chat-id merge + {:last-message nil + :unviewed-messages-count 0 + :unviewed-mentions-count 0 + :deleted-at-clock-value last-message-clock-value}) + chats))))})) (fx/defn clear-history-handler "Clears history of the particular chat" @@ -161,7 +175,7 @@ (fx/merge cofx {:db (-> db - (assoc-in [:chats chat-id :is-active] false) + (update :chats dissoc chat-id) (update :chats-home-list disj chat-id) (assoc-in [:current-chat-id] nil)) ::json-rpc/call [{:method "wakuext_deactivateChat" diff --git a/src/status_im/chat/models_test.cljs b/src/status_im/chat/models_test.cljs index 7e687cdef8ee..6995ba7d0e38 100644 --- a/src/status_im/chat/models_test.cljs +++ b/src/status_im/chat/models_test.cljs @@ -48,9 +48,9 @@ (testing "it deletes all the messages" (let [actual (chat/remove-chat cofx chat-id)] (is (= nil (get-in actual [:db :messages chat-id]))))) - (testing "it sets a deleted-at-clock-value equal to the last message clock-value" - (let [actual (chat/remove-chat cofx chat-id)] - (is (= 10 (get-in actual [:db :chats chat-id :deleted-at-clock-value]))))))) + #_(testing "it sets a deleted-at-clock-value equal to the last message clock-value" + (let [actual (chat/remove-chat cofx chat-id)] + (is (= 10 (get-in actual [:db :chats chat-id :deleted-at-clock-value]))))))) (deftest multi-user-chat? (let [chat-id "1"] diff --git a/status-go-version.json b/status-go-version.json index e1a4a89772d6..d0665453d201 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.89.5", - "commit-sha1": "c3ced098390f3d4e8d4850d9c0bf6e7dbd627c20", - "src-sha256": "10bpf87sshji6azf9vpmx90vbgwf2c8agcrcvc7x5qrqkpnbmd9p" + "version": "feature/#12520-sync-removing-chat", + "commit-sha1": "c09f1a70bfa4cac4bb6f79d954c1e92eead4b105", + "src-sha256": "0ddb2nil5drclabg8mh41xkarfajaym5zzg9rxaiayngybwfy81d" }