From 44fbe7340fbcdbbbfdcb45296e67a8967fa3e928 Mon Sep 17 00:00:00 2001 From: bitsikka Date: Mon, 25 Mar 2019 21:13:13 +0545 Subject: [PATCH] [#7819] fix avoid unnecessary steps when (re)starting new chat [#7819] fix avoid unnecessary steps when (re)starting new chat [#7819] fix avoid unnecessary steps when (re)starting new chat [#7819] fix avoid unnecessary steps when (re)starting new chat [#7819] fix avoid unnecessary steps when (re)starting new chat [#7819] fix avoid unnecessary steps when (re)starting new chat --- src/status_im/chat/models.cljs | 27 +++++++++++++++++++-------- src/status_im/events.cljs | 10 ++++++---- src/status_im/pairing/core.cljs | 2 +- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index 68738d183453..b95be4c6b710 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -264,14 +264,25 @@ (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)))) + [cofx topic {:keys [dont-navigate? dont-sync?] :as opts}] + (let [chats (into [] + (comp (filter :is-active) + (filter :public?) + (filter #(= topic (:chat-id %)))) + (vals (get-in cofx [:db :chats]))) + already-active? (seq chats)] + (if already-active? + (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)) + #(when-not dont-sync? + {:dispatch [:chat.ui/sync-public-chat topic]}))))) (fx/defn disable-chat-cooldown "Turns off chat cooldown (protection against message spamming)" diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 75b5319395dd..b79569750da3 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -762,10 +762,12 @@ (handlers/register-handler-fx :chat.ui/start-public-chat (fn [cofx [_ topic opts]] - (fx/merge - cofx - (chat/start-public-chat topic opts) - (pairing/sync-public-chat topic)))) + (chat/start-public-chat cofx topic opts))) + +(handlers/register-handler-fx + :chat.ui/sync-public-chat + (fn [cofx [_ topic]] + (pairing/sync-public-chat cofx topic))) (handlers/register-handler-fx :chat.ui/remove-chat diff --git a/src/status_im/pairing/core.cljs b/src/status_im/pairing/core.cljs index 8b026c4d11d1..281f1624390b 100644 --- a/src/status_im/pairing/core.cljs +++ b/src/status_im/pairing/core.cljs @@ -254,7 +254,7 @@ :data-store/base-tx [{:transaction (data-store.accounts/save-account-tx new-account) :success-event success-event}]} #(when (:public? chat) - (models.chat/start-public-chat % (:chat-id chat) {:dont-navigate? true}))] + (models.chat/start-public-chat % (:chat-id chat) {:dont-navigate? true :dont-sync? true}))] contacts-fx))) (confirm-message-processed cofx (or (:dedup-id cofx) (:js-obj cofx)))))