Close chat when pop-to-root is called (#20238)

This commit is contained in:
Parvesh Monu 2024-05-29 21:39:44 +05:30 committed by GitHub
parent 7613de74ae
commit 841a6140e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 22 deletions

View File

@ -311,7 +311,7 @@
{:browser-id (:browser-id browser)} {:browser-id (:browser-id browser)}
:browser/screen-id :browser)} :browser/screen-id :browser)}
(navigation/pop-to-root :shell-stack) (navigation/pop-to-root :shell-stack)
(chat.events/close-chat) (chat.events/close-chat (:current-chat-id db))
(navigation/change-tab :browser-stack) (navigation/change-tab :browser-stack)
(update-browser browser) (update-browser browser)
(resolve-url nil)) (resolve-url nil))

View File

@ -144,8 +144,10 @@
(rf/defn close-chat (rf/defn close-chat
{:events [:chat/close]} {:events [:chat/close]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx} chat-id]
(when-let [chat-id (:current-chat-id db)] (let [current-chat-id (:current-chat-id db)
chat-id (or chat-id current-chat-id)]
(when (and current-chat-id (= chat-id current-chat-id))
(chat.state/reset-visible-item) (chat.state/reset-visible-item)
(rf/merge cofx (rf/merge cofx
{:db (-> db {:db (-> db
@ -156,7 +158,7 @@
(link-preview/reset-all) (link-preview/reset-all)
(delete-for-me/sync-all) (delete-for-me/sync-all)
(delete-message/send-all) (delete-message/send-all)
(offload-messages chat-id)))) (offload-messages chat-id)))))
(rf/defn deactivate-chat (rf/defn deactivate-chat
"Deactivate chat in db, no side effects" "Deactivate chat in db, no side effects"
@ -173,7 +175,7 @@
:on-error #(log/error "failed to create public chat" chat-id %)}]} :on-error #(log/error "failed to create public chat" chat-id %)}]}
(clear-history chat-id true) (clear-history chat-id true)
(when (= chat-id (:current-chat-id db)) (when (= chat-id (:current-chat-id db))
(close-chat)))) (close-chat chat-id))))
(rf/defn force-close-chat (rf/defn force-close-chat
[{:keys [db] :as cofx} chat-id] [{:keys [db] :as cofx} chat-id]
@ -201,7 +203,7 @@
[{db :db :as cofx} chat-id animation] [{db :db :as cofx} chat-id animation]
(rf/merge cofx (rf/merge cofx
{:dispatch [(if animation :shell/navigate-to :navigate-to) :chat chat-id animation]} {:dispatch [(if animation :shell/navigate-to :navigate-to) :chat chat-id animation]}
(close-chat) (close-chat chat-id)
(force-close-chat chat-id) (force-close-chat chat-id)
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (assoc db :current-chat-id chat-id)}) {:db (assoc db :current-chat-id chat-id)})

View File

@ -4,6 +4,7 @@
[status-im.contexts.shell.jump-to.events :as shell.events] [status-im.contexts.shell.jump-to.events :as shell.events]
[status-im.contexts.shell.jump-to.state :as shell.state] [status-im.contexts.shell.jump-to.state :as shell.state]
[status-im.contexts.shell.jump-to.utils :as shell.utils] [status-im.contexts.shell.jump-to.utils :as shell.utils]
[status-im.feature-flags :as ff]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn- all-screens-params (defn- all-screens-params
@ -57,12 +58,16 @@
(rf/defn pop-to-root (rf/defn pop-to-root
{:events [:pop-to-root]} {:events [:pop-to-root]}
[{:keys [db]} tab] [{:keys [db]} tab]
(cond->
{:pop-to-root-fx tab {:pop-to-root-fx tab
:db (-> db :db (-> db
(dissoc :shell/floating-screens) (dissoc :shell/floating-screens)
(dissoc :shell/loaded-screens) (dissoc :shell/loaded-screens)
(assoc :view-id (or @shell.state/selected-stack-id :shell))) (assoc :view-id (or @shell.state/selected-stack-id :shell)))
:effects.shell/pop-to-root nil}) :effects.shell/pop-to-root nil}
(and (:current-chat-id db) (not (ff/enabled? ::ff/shell.jump-to)))
(assoc :dispatch [:chat/close (:current-chat-id db)])))
(rf/defn init-root (rf/defn init-root
{:events [:init-root]} {:events [:init-root]}