Skip to content

Commit

Permalink
[#12520] Sync deleted chats
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Oct 4, 2021
1 parent eb5711e commit 6aed8c9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
38 changes: 26 additions & 12 deletions src/status_im/chat/models.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/status_im/chat/models_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"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"
}

0 comments on commit 6aed8c9

Please sign in to comment.