Fix member list in community channels

e0673ad1...6e056348
This commit is contained in:
Andrea Maria Piana 2024-06-10 15:45:55 +01:00
parent 1ee44259c4
commit 34c95c42d1
5 changed files with 55 additions and 28 deletions

View File

@ -38,10 +38,12 @@
:always :always
(update :contacts conj (:id member)))) (update :contacts conj (:id member))))
(defn community-chat-id->channel-id [chat-id] (subs chat-id constants/community-id-length))
(defn decode-chat-id (defn decode-chat-id
[chat-id] [chat-id]
(let [community-id (subs chat-id 0 constants/community-id-length) (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 {:community-id community-id
:channel-id channel-id})) :channel-id channel-id}))

View File

@ -65,7 +65,7 @@
:as chat} (rf/sub [:chats/chat-by-id chat-id]) :as chat} (rf/sub [:chats/chat-by-id chat-id])
pins-count (rf/sub [:chats/pin-messages-count chat-id]) pins-count (rf/sub [:chats/pin-messages-count chat-id])
items (rf/sub [:communities/sorted-community-members-section-list items (rf/sub [:communities/sorted-community-members-section-list
community-id]) community-id chat-id])
theme (quo.theme/use-theme)] theme (quo.theme/use-theme)]
(rn/use-mount (fn [] (rn/use-mount (fn []
(rf/dispatch [:pin-message/load-pin-messages chat-id]))) (rf/dispatch [:pin-message/load-pin-messages chat-id])))

View File

@ -1,6 +1,7 @@
(ns status-im.subs.communities (ns status-im.subs.communities
(:require (:require
[clojure.string :as string] [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] [legacy.status-im.ui.screens.profile.visibility-status.utils :as visibility-status-utils]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.constants :as constants] [status-im.constants :as constants]
@ -49,6 +50,16 @@
(fn [[{:keys [members]}] _] (fn [[{:keys [members]}] _]
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 (defn- keys->names
[public-keys profile] [public-keys profile]
(reduce (fn [acc contact-identity] (reduce (fn [acc contact-identity]
@ -80,10 +91,10 @@
(re-frame/reg-sub (re-frame/reg-sub
:communities/sorted-community-members-section-list :communities/sorted-community-members-section-list
(fn [[_ community-id]] (fn [[_ community-id chat-id]]
(let [profile (re-frame/subscribe [:profile/profile]) (let [profile (re-frame/subscribe [:profile/profile])
members (re-frame/subscribe [:communities/community-members members (re-frame/subscribe [:communities/community-chat-members
community-id]) community-id chat-id])
visibility-status-updates (re-frame/subscribe visibility-status-updates (re-frame/subscribe
[:visibility-status-updates]) [:visibility-status-updates])
my-status-update (re-frame/subscribe my-status-update (re-frame/subscribe

View File

@ -10,7 +10,7 @@
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(def community-id "0x1") (def community-id "0x02b5bdaf5a25fcfe2ee14c501fab1836b8de57f61621080c3d52073d16de0d98d6")
(h/deftest-sub :communities (h/deftest-sub :communities
[sub-name] [sub-name]
@ -461,32 +461,39 @@
[sub-name] [sub-name]
(testing "returns sorted community members per online status" (testing "returns sorted community members per online status"
(let [token-image-eth "data:image/jpeg;base64,/9j/2w" (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 community {:id community-id
:permissions {:access 3} :permissions {:access 3}
:token-images {"ETH" token-image-eth} :token-images {"ETH" token-image-eth}
:name "Community super name" :name "Community super name"
:chats {"89f98a1e-6776-4e5f-8626-8ab9f855253f" :chats {channel-id-1
{:description "x" {:description "x"
:emoji "🎲" :emoji "🎲"
:permissions {:access 1} :permissions {:access 1}
:color "#88B0FF" :color "#88B0FF"
:name "random" :name "random"
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056" :categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
:id "89f98a1e-6776-4e5f-8626-8ab9f855253f" :id channel-id-1
:position 4 :position 4
:can-post? false :can-post? false
:members {"0x04" {"roles" [1]}}} :members nil}
"a076358e-4638-470e-a3fb-584d0a542ce6" channel-id-2
{:description "General channel for the community" {:description "General channel for the community"
:emoji "🥔" :emoji "🥔"
:permissions {:access 1} :permissions {:access 1}
:color "#4360DF" :color "#4360DF"
:name "general" :name "general"
:categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056" :categoryID "0c3c64e7-d56e-439b-a3fb-a946d83cb056"
:id "a076358e-4638-470e-a3fb-584d0a542ce6" :id channel-id-2
:position 0 :position 0
:token-gated? true
:can-post? false :can-post? false
:members {"0x04" {"roles" [1]}}}} :members {"0x01" {"roles" [1]}
"0x02" {"roles" [1]}
"0x05" {"roles" [1]}}}}
:members {"0x01" {"roles" [1]} :members {"0x01" {"roles" [1]}
"0x02" {"roles" [1]} "0x02" {"roles" [1]}
"0x03" {"roles" [1]} "0x03" {"roles" [1]}
@ -500,8 +507,15 @@
:visibility-status-updates :visibility-status-updates
{"0x01" {:status-type constants/visibility-status-always-online} {"0x01" {:status-type constants/visibility-status-always-online}
"0x02" {:status-type constants/visibility-status-always-online}}) "0x02" {:status-type constants/visibility-status-always-online}})
(testing "a non-token gated community should look at all members of a community"
(is (= [{:title (i18n/label :t/online) (is (= [{:title (i18n/label :t/online)
:data ["0x01" "0x02"]} :data ["0x01" "0x02"]}
{:title (i18n/label :t/offline) {:title (i18n/label :t/offline)
:data ["0x03" "0x04"]}] :data ["0x03" "0x04"]}]
(rf/sub [sub-name community-id])))))) (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])))))))

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.180.31", "version": "v0.181.31",
"commit-sha1": "e0673ad1ffec65e3bd96a46b5054fc2d36071cc4", "commit-sha1": "6e056348e6d28f962167118612826f1ef0e47b22",
"src-sha256": "15y3fl0q8kqxbsqj9snyg7spaqj09xid9rfza7l5zpk8p0ajqnmk" "src-sha256": "1qvfwk28sg93basjzy8r55qz8pk9xg0h7kxv5ykxkbfh4q17a1ns"
} }