From 8720ce4a24b0d8b10c471e515145edb22b2ba96a Mon Sep 17 00:00:00 2001 From: bitsikka Date: Sat, 13 Apr 2019 17:40:54 +0545 Subject: [PATCH] [#7819] fix - avoid unnecessary effects when joining/syncing already active public chat --- src/status_im/chat/models.cljs | 23 +++++++++++++------ src/status_im/pairing/core.cljs | 1 - src/status_im/utils/universal_links/core.cljs | 6 ++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index cf5fc6b05343..ff4fc1c3bd2a 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -41,6 +41,12 @@ ([cofx chat-id] (public-chat? (get-chat cofx chat-id)))) +(defn active-chat? + ([chat] + (:is-active chat)) + ([cofx chat-id] + (active-chat? (get-chat cofx chat-id)))) + (defn group-chat? ([chat] (and (multi-user-chat? chat) @@ -289,13 +295,16 @@ (fx/defn start-public-chat "Starts a new public chat" [cofx topic {:keys [dont-navigate?] :as opts}] - (fx/merge cofx - (add-public-chat topic) - #(when-not dont-navigate? - (navigate-to-chat % topic opts)) - (public-chat/join-public-chat topic) - (when platform/desktop? - (desktop.events/change-tab :home)))) + (if (active-chat? cofx topic) + (when-not dont-navigate? + (navigate-to-chat cofx topic opts)) + (fx/merge cofx + (add-public-chat topic) + #(when-not dont-navigate? + (navigate-to-chat % topic opts)) + (public-chat/join-public-chat topic) + #(when platform/desktop? + (desktop.events/change-tab % :home))))) (fx/defn disable-chat-cooldown "Turns off chat cooldown (protection against message spamming)" diff --git a/src/status_im/pairing/core.cljs b/src/status_im/pairing/core.cljs index 7e95da9f697a..763b8aaad768 100644 --- a/src/status_im/pairing/core.cljs +++ b/src/status_im/pairing/core.cljs @@ -155,7 +155,6 @@ (let [contacts (:contacts/contacts db) contact-batches (partition-all contact-batch-n (vals contacts))] (concat (mapv contact-batch->sync-installation-message contact-batches) - [(sync-installation-account-message cofx)] (chats->sync-installation-messages cofx)))) diff --git a/src/status_im/utils/universal_links/core.cljs b/src/status_im/utils/universal_links/core.cljs index 7a0fc3a7772c..b2230424a51a 100644 --- a/src/status_im/utils/universal_links/core.cljs +++ b/src/status_im/utils/universal_links/core.cljs @@ -5,6 +5,7 @@ [re-frame.core :as re-frame] [status-im.accounts.db :as accounts.db] [status-im.chat.models :as chat] + [status-im.pairing.core :as pairing] [status-im.extensions.registry :as extensions.registry] [status-im.ui.components.list-selection :as list-selection] [status-im.ui.components.react :as react] @@ -65,7 +66,10 @@ (fx/defn handle-public-chat [cofx public-chat] (log/info "universal-links: handling public chat" public-chat) - (chat/start-public-chat cofx public-chat {})) + (fx/merge + cofx + (chat/start-public-chat public-chat {}) + (pairing/sync-public-chat public-chat))) (fx/defn handle-view-profile [{:keys [db] :as cofx} public-key] (log/info "universal-links: handling view profile" public-key)