Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#12520] Sync deleted chats #12662

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.6",
"commit-sha1": "7701368b142ad073f76d678095114b1388cce4b3",
"src-sha256": "0cgl5vhbn943sbzxzrnmpipxgyvlp4p3k96m5qp86cpw40rnhv9w"
"version": "v0.89.7",
"commit-sha1": "4de912babad60c8ac556277ffc79026fc4cabdc4",
"src-sha256": "17lkgq6rciq1snnxjflxy6wqianyi0wkgjdk6rplz5yy2y91rv7v"
}