diff --git a/src/status_im/contexts/chat/events.cljs b/src/status_im/contexts/chat/events.cljs index 06b1a8370757..1aa4dc033309 100644 --- a/src/status_im/contexts/chat/events.cljs +++ b/src/status_im/contexts/chat/events.cljs @@ -206,7 +206,9 @@ {:events [:chat/navigate-to-chat]} [{db :db :as cofx} chat-id animation] (rf/merge cofx - {:dispatch [(if animation :shell/navigate-to :navigate-to) :chat chat-id animation]} + {:fx [[:dispatch [(if animation :shell/navigate-to :navigate-to) :chat chat-id animation]] + (when-let [community-id (get-in db [:chats chat-id :community-id])] + [:dispatch [:chat.ui/fetch-community community-id]])]} (close-chat) (force-close-chat chat-id) (fn [{:keys [db]}] diff --git a/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs b/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs index 70a640fe4ed9..de177f51674a 100644 --- a/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs +++ b/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs @@ -45,7 +45,7 @@ (defn community-resolved [{:keys [db]} [community-id community]] (when community - {:db (update db :communities/resolve-community-info dissoc community-id) + {:db (update db :communities/fetching-community-info dissoc community-id) :fx [[:dispatch [:communities/handle-community community]] [:dispatch [:chat.ui/cache-link-preview-data (community-link community-id) community]]]})) @@ -54,14 +54,14 @@ (defn community-failed-to-resolve [{:keys [db]} [community-id]] - {:db (update db :communities/resolve-community-info dissoc community-id)}) + {:db (update db :communities/fetching-community-info dissoc community-id)}) (rf/reg-event-fx :chat.ui/community-failed-to-resolve community-failed-to-resolve) (defn fetch-community [{:keys [db]} [community-id]] - (when community-id - {:db (assoc-in db [:communities/resolve-community-info community-id] true) + (when (and community-id (not (get-in db [:communities/fetching-community-info community-id]))) + {:db (assoc-in db [:communities/fetching-community-info community-id] true) :json-rpc/call [{:method "wakuext_fetchCommunity" :params [{:CommunityKey community-id :TryDatabase true diff --git a/src/status_im/contexts/chat/messenger/messages/link_preview/events_test.cljs b/src/status_im/contexts/chat/messenger/messages/link_preview/events_test.cljs index 1c5fda33a973..cb278c5999b3 100644 --- a/src/status_im/contexts/chat/messenger/messages/link_preview/events_test.cljs +++ b/src/status_im/contexts/chat/messenger/messages/link_preview/events_test.cljs @@ -8,7 +8,7 @@ (t/testing "with community id" (t/testing "update resolving indicator in db" (t/is (match? - {:db {:communities/resolve-community-info {"community-id" true}}} + {:db {:communities/fetching-community-info {"community-id" true}}} (sut/fetch-community {} ["community-id"])))) (t/testing "call the fetch community rpc method with correct community id" (t/is (match? @@ -28,21 +28,21 @@ (t/testing "remove community id from resolving indicator in db" (t/is (match? nil - (get-in (sut/community-failed-to-resolve {:db {:communities/resolve-community-info + (get-in (sut/community-failed-to-resolve {:db {:communities/fetching-community-info {"community-id" true}}} ["community-id"]) - [:db :communities/resolve-community-info "community-id"])))))) + [:db :communities/fetching-community-info "community-id"])))))) (t/deftest community-resolved (with-redefs [sut/community-link (fn [id] (str "community-link+" id))] (t/testing "given a community" - (let [cofx {:db {:communities/resolve-community-info {"community-id" true}}} + (let [cofx {:db {:communities/fetching-community-info {"community-id" true}}} arg ["community-id" {:id "community-id"}]] (t/testing "remove community id from resolving indicator in db" (t/is (match? nil (get-in (sut/community-resolved cofx arg) - [:db :communities/resolve-community-info "community-id"])))) + [:db :communities/fetching-community-info "community-id"])))) (t/testing "dispatch fxs" (t/is (match? {:fx [[:dispatch [:communities/handle-community {:id "community-id"}]] @@ -51,7 +51,7 @@ {:id "community-id"}]]]} (sut/community-resolved cofx arg)))))) (t/testing "given a joined community" - (let [cofx {:db {:communities/resolve-community-info {"community-id" true}}} + (let [cofx {:db {:communities/fetching-community-info {"community-id" true}}} arg ["community-id" {:id "community-id" :joined true}]] (t/testing "dispatch fxs, do not spectate community" (t/is (match? @@ -61,7 +61,7 @@ {:id "community-id"}]]]} (sut/community-resolved cofx arg)))))) (t/testing "given a token-gated community" - (let [cofx {:db {:communities/resolve-community-info {"community-id" true}}} + (let [cofx {:db {:communities/fetching-community-info {"community-id" true}}} arg ["community-id" {:id "community-id" :tokenPermissions [1]}]] (t/testing "dispatch fxs, do not spectate community" (t/is (match? diff --git a/src/status_im/contexts/communities/events.cljs b/src/status_im/contexts/communities/events.cljs index 8aa7defea4f7..c9589f0b2568 100644 --- a/src/status_im/contexts/communities/events.cljs +++ b/src/status_im/contexts/communities/events.cljs @@ -69,7 +69,7 @@ (let [{:keys [token-permissions token-permissions-check joined id] :as community} (<-rpc community-js) - has-token-permissions? (not (seq token-permissions))] + has-token-permissions? (seq token-permissions)] {:db (assoc-in db [:communities id] community) :fx [(when (and has-token-permissions? (not joined)) [:dispatch [:chat.ui/spectate-community id]]) diff --git a/src/status_im/contexts/communities/overview/view.cljs b/src/status_im/contexts/communities/overview/view.cljs index a90755146aa8..56f51ff0c0f3 100644 --- a/src/status_im/contexts/communities/overview/view.cljs +++ b/src/status_im/contexts/communities/overview/view.cljs @@ -376,6 +376,7 @@ (defn overview [id] + (rf/dispatch [:chat.ui/fetch-community id]) (let [id (or id (rf/sub [:get-screen-params :community-overview])) customization-color (rf/sub [:profile/customization-color])] [rn/view {:style style/community-overview-container} diff --git a/src/status_im/subs/communities.cljs b/src/status_im/subs/communities.cljs index 4a2c720a4bb9..665bf604cf1e 100644 --- a/src/status_im/subs/communities.cljs +++ b/src/status_im/subs/communities.cljs @@ -8,7 +8,7 @@ (re-frame/reg-sub :communities/fetching-community - :<- [:communities/resolve-community-info] + :<- [:communities/fetching-community-info] (fn [info [_ id]] (get info id))) diff --git a/src/status_im/subs/root.cljs b/src/status_im/subs/root.cljs index 13d65c218dca..a6f80d84eab8 100644 --- a/src/status_im/subs/root.cljs +++ b/src/status_im/subs/root.cljs @@ -140,7 +140,7 @@ (reg-root-key-sub :communities/channels-permissions :community-channels-permissions) (reg-root-key-sub :communities/requests-to-join :communities/requests-to-join) (reg-root-key-sub :communities/community-id-input :communities/community-id-input) -(reg-root-key-sub :communities/resolve-community-info :communities/resolve-community-info) +(reg-root-key-sub :communities/fetching-community-info :communities/fetching-community-info) (reg-root-key-sub :communities/my-pending-requests-to-join :communities/my-pending-requests-to-join) (reg-root-key-sub :communities/collapsed-categories :communities/collapsed-categories) (reg-root-key-sub :communities/selected-tab :communities/selected-tab)