From 1186b73be89691600e7e5b76f86012519d13898a Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Wed, 1 Aug 2018 11:27:38 -0600 Subject: [PATCH] Set current-chat-id to nil once chat is deleted (desktop only) --- src/status_im/chat/models.cljs | 9 ++++++--- src/status_im/ui/components/desktop/events.cljs | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index c2b0357f2f..db7782ae9c 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -2,6 +2,7 @@ (:require [status-im.ui.components.styles :as styles] [status-im.utils.gfycat.core :as gfycat] [status-im.transport.utils :as transport.utils] + [status-im.utils.platform :as platform] [status-im.utils.clocks :as utils.clocks] [status-im.transport.message.core :as transport.message] [status-im.data-store.chats :as chats-store] @@ -101,9 +102,11 @@ (transport.utils/unsubscribe-from-chat chat-id cofx))) (defn- deactivate-chat [chat-id {:keys [db now] :as cofx}] - (assoc-in {:db db - :data-store/tx [(chats-store/deactivate-chat-tx chat-id now)]} - [:db :chats chat-id :is-active] false)) + (cond-> (assoc-in {:db db + :data-store/tx [(chats-store/deactivate-chat-tx chat-id now)]} + [:db :chats chat-id :is-active] false) + platform/desktop? + (assoc-in [:db :current-chat-id] nil))) ;; TODO: There's a race condition here, as the removal of the filter (async) ;; is done at the same time as the removal of the chat, so a message diff --git a/src/status_im/ui/components/desktop/events.cljs b/src/status_im/ui/components/desktop/events.cljs index d1406c4711..dd931817cd 100644 --- a/src/status_im/ui/components/desktop/events.cljs +++ b/src/status_im/ui/components/desktop/events.cljs @@ -6,4 +6,6 @@ :show-desktop-tab (fn [{:keys [db] :as cofx} [_ tab-name]] {:db (assoc-in db [:desktop/desktop :tab-view-id] tab-name) - :dispatch [:navigate-to (if (= tab-name :home) :chat :home)]})) + :dispatch [:navigate-to (if (and (= tab-name :home) (:current-chat-id db)) + :chat + :home)]}))