diff --git a/src/legacy/status_im/chat/models/loading.cljs b/src/legacy/status_im/chat/models/loading.cljs index d0d33937b3..91e8a43538 100644 --- a/src/legacy/status_im/chat/models/loading.cljs +++ b/src/legacy/status_im/chat/models/loading.cljs @@ -18,25 +18,24 @@ clock-value "0x0000000000000000000000000000000000000000000000000000000000000000")) -(rf/defn update-chats-in-app-db - {:events [:chats-list/load-success]} - [{:keys [db]} ^js new-chats-js] - (let [{:keys [all-chats chats-home-list]} - (reduce (fn [acc ^js chat-js] - (let [{:keys [chat-id profile-public-key timeline? community-id active] :as chat} - (data-store.chats/<-rpc-js chat-js)] - (cond-> acc - (and (not profile-public-key) (not timeline?) (not community-id) active) - (update :chats-home-list conj chat-id) - :always - (assoc-in [:all-chats chat-id] chat)))) - {:all-chats {} - :chats-home-list #{}} - new-chats-js)] - {:db (assoc db - :chats all-chats - :chats-home-list chats-home-list - :chats/loading? false)})) +(rf/reg-event-fx :chats-list/load-success + (fn [{:keys [db]} [^js new-chats-js]] + (let [{:keys [all-chats chats-home-list]} + (reduce (fn [acc ^js chat-js] + (let [{:keys [chat-id profile-public-key timeline? community-id active] :as chat} + (data-store.chats/<-rpc-js chat-js)] + (cond-> acc + (and (not profile-public-key) (not timeline?) (not community-id) active) + (update :chats-home-list conj chat-id) + :always + (assoc-in [:all-chats chat-id] chat)))) + {:all-chats {} + :chats-home-list #{}} + new-chats-js)] + {:db (-> db + (update :chats merge all-chats) + (update :chats-home-list into chats-home-list) + (assoc :chats/loading? false))}))) (rf/defn load-chat-success {:events [:chats-list/load-chat-success]} diff --git a/src/legacy/status_im/data_store/chats.cljs b/src/legacy/status_im/data_store/chats.cljs index ab685cb8b1..392699d059 100644 --- a/src/legacy/status_im/data_store/chats.cljs +++ b/src/legacy/status_im/data_store/chats.cljs @@ -134,9 +134,9 @@ unmarshal-members)) (re-frame/reg-fx :fetch-chats-preview - (fn [{:keys [on-success]}] + (fn [{:keys [on-success chat-preview-type]}] (json-rpc/call {:method "wakuext_chatsPreview" - :params [] + :params [chat-preview-type] :js-response true :on-success #(on-success ^js %) :on-error #(log/error "failed to fetch chats" 0 -1 %)}))) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index f298b0a249..e2ec395ba9 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -76,6 +76,9 @@ (def ^:const timeline-chat-type 5) (def ^:const community-chat-type 6) +(def ^:const chat-preview-type-community 0) +(def ^:const chat-preview-type-non-community 1) + (def ^:const contact-request-message-state-none 0) (def ^:const contact-request-message-state-pending 1) (def ^:const contact-request-message-state-accepted 2) diff --git a/src/status_im/contexts/profile/login/events.cljs b/src/status_im/contexts/profile/login/events.cljs index 9df55d2b00..854c623ed8 100644 --- a/src/status_im/contexts/profile/login/events.cljs +++ b/src/status_im/contexts/profile/login/events.cljs @@ -4,6 +4,7 @@ [native-module.core :as native-module] [status-im.common.keychain.events :as keychain] [status-im.config :as config] + [status-im.constants :as constants] status-im.contexts.profile.login.effects [status-im.contexts.profile.rpc :as profile.rpc] [taoensso.timbre :as log] @@ -131,10 +132,15 @@ (let [new-account? (get db :onboarding/new-account?)] {:db (assoc db :messenger/started? true) :fx [[:fetch-chats-preview - {:on-success (fn [result] - (rf/dispatch [:chats-list/load-success result]) - (rf/dispatch [:communities/get-user-requests-to-join]) - (rf/dispatch [:profile.login/get-chats-callback]))}] + {:chat-preview-type constants/chat-preview-type-non-community + :on-success (fn [result] + (rf/dispatch [:chats-list/load-success result]) + (rf/dispatch [:profile.login/get-chats-callback]))}] + [:fetch-chats-preview + {:chat-preview-type constants/chat-preview-type-community + :on-success (fn [result] + (rf/dispatch [:chats-list/load-success result]) + (rf/dispatch [:communities/get-user-requests-to-join]))}] (when (and (:syncing/fallback-flow? db) (:syncing/installation-id db)) [:dispatch [:pairing/finish-seed-phrase-fallback-syncing]]) (when-not new-account?