From 94453634678799a40f8a9979fa0070d0ebeef8a3 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 3 Jun 2024 15:57:22 +0100 Subject: [PATCH] fix_: spectate communities only when opening --- src/status_im/contexts/communities/events.cljs | 9 +++++---- src/status_im/contexts/communities/events_test.cljs | 4 +--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/status_im/contexts/communities/events.cljs b/src/status_im/contexts/communities/events.cljs index ad1c6e0037..f11fffbddd 100644 --- a/src/status_im/contexts/communities/events.cljs +++ b/src/status_im/contexts/communities/events.cljs @@ -22,17 +22,17 @@ [{:keys [db]} [community-js]] (when community-js (let [{:keys [clock - token-permissions-check joined id last-opened-at] + token-permissions-check id last-opened-at] :as community} (data-store.communities/<-rpc community-js) previous-last-opened-at (get-in db [:communities id :last-opened-at])] (when (> clock (get-in db [:communities id :clock])) {:db (assoc-in db [:communities id] (assoc community :last-opened-at (max last-opened-at previous-last-opened-at))) + ;; NOTE(cammellos): these two looks suspicious, we should not check for permissions at + ;; every event signalled :fx [[:dispatch [:communities/check-permissions-to-join-community-with-all-addresses id]] - (when (not joined) - [:dispatch [:chat.ui/spectate-community id]]) (when (nil? token-permissions-check) [:dispatch [:communities/check-permissions-to-join-community id]])]})))) @@ -350,7 +350,8 @@ (navigate-to-serialized-community community-id) (rf/merge cofx - {:fx [[:dispatch + {:fx [[:dispatch [:chat.ui/spectate-community community-id]] + [:dispatch [:communities/fetch-community {:community-id community-id :update-last-opened-at? true}]] diff --git a/src/status_im/contexts/communities/events_test.cljs b/src/status_im/contexts/communities/events_test.cljs index 57788e6197..35780a3ca1 100644 --- a/src/status_im/contexts/communities/events_test.cljs +++ b/src/status_im/contexts/communities/events_test.cljs @@ -178,7 +178,6 @@ (is (match? [[:dispatch [:communities/check-permissions-to-join-community-with-all-addresses community-id]] - [:dispatch [:chat.ui/spectate-community community-id]] [:dispatch [:communities/check-permissions-to-join-community community-id]]] (filter some? (:fx effects)))))) @@ -196,8 +195,7 @@ effects (events/handle-community {} [community])] (is (match? [[:dispatch - [:communities/check-permissions-to-join-community-with-all-addresses community-id]] - [:dispatch [:chat.ui/spectate-community community-id]]] + [:communities/check-permissions-to-join-community-with-all-addresses community-id]]] (filter some? (:fx effects)))))) (testing "given a community with lower clock" (let [effects (events/handle-community {:db {:communities {community-id {:clock 3}}}} [community])]