Skip to content

Commit

Permalink
feat: re-fetch community info in community overview and channel
Browse files Browse the repository at this point in the history
  • Loading branch information
yqrashawn committed Jan 11, 2024
1 parent 0f43daa commit c992894
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/status_im/contexts/chat/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]}))
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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"}]]
Expand All @@ -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?
Expand All @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/contexts/communities/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand Down
1 change: 1 addition & 0 deletions src/status_im/contexts/communities/overview/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/subs/communities.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
2 changes: 1 addition & 1 deletion src/status_im/subs/root.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c992894

Please sign in to comment.