Fix member list in community channels

b665d68d...4c738637
This commit is contained in:
Andrea Maria Piana 2024-06-10 15:45:55 +01:00
parent 24b77811d8
commit b8d327b761
5 changed files with 55 additions and 28 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.180.30",
"commit-sha1": "b665d68d0cff7cd4521ac8791fcf6eac29b23cd9",
"src-sha256": "1bpj3x2bmrh7whhx9sb2wgwc4q8knm4c3rzvimp0s84fsvna5ynq"
"version": "perf/remove-member-list",
"commit-sha1": "4c73863706180299de40e02a52aec8c41b2b228c",
"src-sha256": "1srb2a6c6sak4zhv6bjv2cj9v0521bccg0bvdh192abd3b4ws1fa"
}