diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index 001ab283cff5..dc682c6ee6bf 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -281,14 +281,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? sync?] :or {sync? true} :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 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 7b9f283eccc4..bbedc433b417 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -769,10 +769,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 bf00bce2b5b5..a7eca8a7491b 100644 --- a/src/status_im/pairing/core.cljs +++ b/src/status_im/pairing/core.cljs @@ -272,7 +272,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 :sync? false}))] contacts-fx))) (confirm-message-processed cofx (or (:dedup-id cofx) (:js-obj cofx)))))