fix_: spectate communities only when opening

This commit is contained in:
Andrea Maria Piana 2024-06-03 15:57:22 +01:00
parent 5bad8de886
commit 9445363467
2 changed files with 6 additions and 7 deletions

View File

@ -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}]]

View File

@ -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])]