From 34c95c42d124203573d84b62f1841e983b0b82cc Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 10 Jun 2024 15:45:55 +0100 Subject: [PATCH] Fix member list in community channels https://github.com/status-im/status-go/compare/e0673ad1...6e056348 --- src/legacy/status_im/data_store/chats.cljs | 4 +- .../actions/channel_view_details/view.cljs | 2 +- src/status_im/subs/communities.cljs | 17 ++++-- src/status_im/subs/communities_test.cljs | 54 ++++++++++++------- status-go-version.json | 6 +-- 5 files changed, 55 insertions(+), 28 deletions(-) diff --git a/src/legacy/status_im/data_store/chats.cljs b/src/legacy/status_im/data_store/chats.cljs index f023f1f94f..ab685cb8b1 100644 --- a/src/legacy/status_im/data_store/chats.cljs +++ b/src/legacy/status_im/data_store/chats.cljs @@ -38,10 +38,12 @@ :always (update :contacts conj (:id member)))) +(defn community-chat-id->channel-id [chat-id] (subs chat-id constants/community-id-length)) + (defn decode-chat-id [chat-id] (let [community-id (subs chat-id 0 constants/community-id-length) - channel-id (subs chat-id constants/community-id-length)] + channel-id (community-chat-id->channel-id chat-id)] {:community-id community-id :channel-id channel-id})) diff --git a/src/status_im/contexts/communities/actions/channel_view_details/view.cljs b/src/status_im/contexts/communities/actions/channel_view_details/view.cljs index 23ace086f8..9547aae8a6 100644 --- a/src/status_im/contexts/communities/actions/channel_view_details/view.cljs +++ b/src/status_im/contexts/communities/actions/channel_view_details/view.cljs @@ -65,7 +65,7 @@ :as chat} (rf/sub [:chats/chat-by-id chat-id]) pins-count (rf/sub [:chats/pin-messages-count chat-id]) items (rf/sub [:communities/sorted-community-members-section-list - community-id]) + community-id chat-id]) theme (quo.theme/use-theme)] (rn/use-mount (fn [] (rf/dispatch [:pin-message/load-pin-messages chat-id]))) diff --git a/src/status_im/subs/communities.cljs b/src/status_im/subs/communities.cljs index 2967f24b76..61e5dfb15b 100644 --- a/src/status_im/subs/communities.cljs +++ b/src/status_im/subs/communities.cljs @@ -1,6 +1,7 @@ (ns status-im.subs.communities (:require [clojure.string :as string] + [legacy.status-im.data-store.chats :as data-store.chats] [legacy.status-im.ui.screens.profile.visibility-status.utils :as visibility-status-utils] [re-frame.core :as re-frame] [status-im.constants :as constants] @@ -49,6 +50,16 @@ (fn [[{:keys [members]}] _] members)) +(re-frame/reg-sub + :communities/community-chat-members + (fn [[_ community-id]] + [(re-frame/subscribe [:communities/community community-id])]) + (fn [[{:keys [members chats]}] [_ _ chat-id]] + (let [channel-id (data-store.chats/community-chat-id->channel-id chat-id)] + (if (get-in chats [channel-id :token-gated?]) + (get-in chats [channel-id :members]) + members)))) + (defn- keys->names [public-keys profile] (reduce (fn [acc contact-identity] @@ -80,10 +91,10 @@ (re-frame/reg-sub :communities/sorted-community-members-section-list - (fn [[_ community-id]] + (fn [[_ community-id chat-id]] (let [profile (re-frame/subscribe [:profile/profile]) - members (re-frame/subscribe [:communities/community-members - community-id]) + members (re-frame/subscribe [:communities/community-chat-members + community-id chat-id]) visibility-status-updates (re-frame/subscribe [:visibility-status-updates]) my-status-update (re-frame/subscribe diff --git a/src/status_im/subs/communities_test.cljs b/src/status_im/subs/communities_test.cljs index bea8cb54bc..9bae83729d 100644 --- a/src/status_im/subs/communities_test.cljs +++ b/src/status_im/subs/communities_test.cljs @@ -10,7 +10,7 @@ [utils.i18n :as i18n] [utils.re-frame :as rf])) -(def community-id "0x1") +(def community-id "0x02b5bdaf5a25fcfe2ee14c501fab1836b8de57f61621080c3d52073d16de0d98d6") (h/deftest-sub :communities [sub-name] @@ -461,32 +461,39 @@ [sub-name] (testing "returns sorted community members per online status" (let [token-image-eth "data:image/jpeg;base64,/9j/2w" + channel-id-1 "89f98a1e-6776-4e5f-8626-8ab9f855253f" + channel-id-2 "a076358e-4638-470e-a3fb-584d0a542ce6" + chat-id-1 (str community-id channel-id-1) + chat-id-2 (str community-id channel-id-2) community {:id community-id :permissions {:access 3} :token-images {"ETH" token-image-eth} :name "Community super name" - :chats {"89f98a1e-6776-4e5f-8626-8ab9f855253f" + :chats {channel-id-1 {:description "x" :emoji "🎲" :permissions {:access 1} :color "#88B0FF" :name "random" :categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056" - :id "89f98a1e-6776-4e5f-8626-8ab9f855253f" + :id channel-id-1 :position 4 :can-post? false - :members {"0x04" {"roles" [1]}}} - "a076358e-4638-470e-a3fb-584d0a542ce6" - {:description "General channel for the community" - :emoji "🥔" - :permissions {:access 1} - :color "#4360DF" - :name "general" - :categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056" - :id "a076358e-4638-470e-a3fb-584d0a542ce6" - :position 0 - :can-post? false - :members {"0x04" {"roles" [1]}}}} + :members nil} + channel-id-2 + {:description "General channel for the community" + :emoji "🥔" + :permissions {:access 1} + :color "#4360DF" + :name "general" + :categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056" + :id channel-id-2 + :position 0 + :token-gated? true + :can-post? false + :members {"0x01" {"roles" [1]} + "0x02" {"roles" [1]} + "0x05" {"roles" [1]}}}} :members {"0x01" {"roles" [1]} "0x02" {"roles" [1]} "0x03" {"roles" [1]} @@ -500,8 +507,15 @@ :visibility-status-updates {"0x01" {:status-type constants/visibility-status-always-online} "0x02" {:status-type constants/visibility-status-always-online}}) - (is (= [{:title (i18n/label :t/online) - :data ["0x01" "0x02"]} - {:title (i18n/label :t/offline) - :data ["0x03" "0x04"]}] - (rf/sub [sub-name community-id])))))) + (testing "a non-token gated community should look at all members of a community" + (is (= [{:title (i18n/label :t/online) + :data ["0x01" "0x02"]} + {:title (i18n/label :t/offline) + :data ["0x03" "0x04"]}] + (rf/sub [sub-name community-id chat-id-1])))) + (testing "a token gated community should use the members option in the channel" + (is (= [{:title (i18n/label :t/online) + :data ["0x01" "0x02"]} + {:title (i18n/label :t/offline) + :data ["0x05"]}] + (rf/sub [sub-name community-id chat-id-2]))))))) diff --git a/status-go-version.json b/status-go-version.json index 8a4b03640d..62115adb5c 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.180.31", - "commit-sha1": "e0673ad1ffec65e3bd96a46b5054fc2d36071cc4", - "src-sha256": "15y3fl0q8kqxbsqj9snyg7spaqj09xid9rfza7l5zpk8p0ajqnmk" + "version": "v0.181.31", + "commit-sha1": "6e056348e6d28f962167118612826f1ef0e47b22", + "src-sha256": "1qvfwk28sg93basjzy8r55qz8pk9xg0h7kxv5ykxkbfh4q17a1ns" }