Compare commits

...
15 changed files with 145 additions and 340 deletions
+1 -1
View File
@@ -1 +1 @@
1.25.0
2.27.0
@@ -4,13 +4,6 @@
[clojure.walk :as walk]
[status-im.constants :as constants]))
(defn rpc->channel-permissions
[rpc-channels-permissions]
(update-vals rpc-channels-permissions
(fn [{:keys [viewAndPostPermissions viewOnlyPermissions]}]
{:view-only (set/rename-keys viewOnlyPermissions {:satisfied :satisfied?})
:view-and-post (set/rename-keys viewAndPostPermissions {:satisfied :satisfied?})})))
(defn <-revealed-accounts-rpc
[accounts]
(mapv
@@ -34,8 +27,9 @@
(assoc acc
(name k)
(-> v
(assoc :can-post? (:canPost v))
(dissoc :canPost)
(assoc :token-gated? (:tokenGated v)
:can-post? (:canPost v))
(dissoc :canPost :tokenGated)
(update :members walk/stringify-keys))))
{}
chats))
@@ -1,23 +0,0 @@
(ns legacy.status-im.data-store.communities-test
(:require
[cljs.test :refer [deftest is]]
[legacy.status-im.data-store.communities :as sut]))
(def permissions
{"community-id-chat-1"
{:viewOnlyPermissions {:satisfied false
:permissions {:token-permission-id-01 {:criteria [false]}}}
:viewAndPostPermissions {:satisfied true :permissions {}}}
"community-id-chat-2"
{:viewOnlyPermissions {:satisfied true :permissions {}}
:viewAndPostPermissions {:satisfied true :permissions {}}}})
(deftest rpc->channel-permissions-test
(is (= {"community-id-chat-1"
{:view-only {:satisfied? false
:permissions {:token-permission-id-01 {:criteria [false]}}}
:view-and-post {:satisfied? true :permissions {}}}
"community-id-chat-2"
{:view-only {:satisfied? true :permissions {}}
:view-and-post {:satisfied? true :permissions {}}}}
(sut/rpc->channel-permissions permissions))))
@@ -53,7 +53,7 @@
:style {:color (colors/theme-colors colors/danger-50 colors/danger-60 theme)}}
error-message]])
(when (= description :top)
(when (and (= description :top) role)
[rn/view
{:style style/description-top}
[text/text
@@ -61,7 +61,8 @@
(rf/dispatch [:communities/get-permissioned-balances id])
(fn []
(let [{:keys [name color images]} (rf/sub [:communities/community id])
{:keys [highest-permission-role]} (rf/sub [:community/token-gated-overview id])
{:keys [checking?
highest-permission-role]} (rf/sub [:community/token-gated-overview id])
accounts (rf/sub [:wallet/accounts-without-watched-accounts])
selected-addresses (rf/sub [:communities/selected-permission-addresses id])
share-all-addresses? (rf/sub [:communities/share-all-addresses? id])
@@ -105,7 +106,8 @@
{:actions :two-actions
:button-one-label (i18n/label :t/confirm-changes)
:button-one-props {:customization-color color
:disabled? (or (empty? selected-addresses)
:disabled? (or checking?
(empty? selected-addresses)
(not highest-permission-role)
(not unsaved-address-changes?))
:on-press (fn []
@@ -123,9 +125,10 @@
(not highest-permission-role))
:top-error
:top)
:role (role-keyword highest-permission-role)
:role (when-not checking? (role-keyword highest-permission-role))
:error-message (cond
(empty? selected-addresses) (i18n/label :t/no-addresses-selected)
(not highest-permission-role) (i18n/label
:t/addresses-dont-contain-tokens-needed)
:else nil)}]]))))
@@ -14,6 +14,7 @@
:canManageUsers :can-manage-users?
:categoryID :category-id
:canPost :can-post?
:tokenGated :token-gated?
:isControlNode :is-control-node?
:pinMessageAllMembersEnabled :pin-message-all-members-enabled
:isMember :is-member?
+22 -19
View File
@@ -21,7 +21,8 @@
(defn handle-community
[{:keys [db]} [community-js]]
(when community-js
(let [{:keys [token-permissions
(let [{:keys [clock
token-permissions
token-permissions-check joined id]
:as community} (data-store.communities/<-rpc community-js)
has-channel-perm? (fn [id-perm-tuple]
@@ -30,16 +31,15 @@
(=
type
constants/community-token-permission-can-view-and-post-channel))))]
{:db (assoc-in db [:communities id] community)
:fx [[:dispatch [:communities/initialize-permission-addresses id]]
(when (not joined)
[:dispatch [:chat.ui/spectate-community id]])
(when (nil? token-permissions-check)
[:dispatch [:communities/check-permissions-to-join-community id]])
(when (some has-channel-perm? token-permissions)
[:dispatch [:communities/check-all-community-channels-permissions id]])
(when joined
[:dispatch [:communities/get-revealed-accounts id]])]})))
(when (> clock (get-in db [:communities id :clock]))
{:db (assoc-in db [:communities id] community)
:fx [[:dispatch [:communities/initialize-permission-addresses id]]
(when (not joined)
[:dispatch [:chat.ui/spectate-community id]])
(when (nil? token-permissions-check)
[:dispatch [:communities/check-permissions-to-join-community id]])
(when joined
[:dispatch [:communities/get-revealed-accounts id]])]}))))
(rf/reg-event-fx :communities/handle-community handle-community)
@@ -223,16 +223,19 @@
(defn toggle-share-all-addresses
[{:keys [db]} [community-id]]
(let [share-all-addresses? (get-in db [:communities community-id :share-all-addresses?])
accounts (utils/sorted-non-watch-only-accounts db)
addresses (set (map :address accounts))]
(let [share-all-addresses? (get-in db [:communities community-id :share-all-addresses?])
next-share-all-addresses? (not share-all-addresses?)
accounts (utils/sorted-non-watch-only-accounts db)
addresses (set (map :address accounts))]
{:db (update-in db
[:communities community-id]
(fn [community]
(-> community
(assoc :share-all-addresses? (not share-all-addresses?))
(cond-> (not share-all-addresses?)
(assoc :selected-permission-addresses addresses)))))}))
assoc
:share-all-addresses? next-share-all-addresses?
:selected-permission-addresses addresses)
:fx [(when (and community-id next-share-all-addresses?)
[:dispatch
[:communities/check-permissions-to-join-community community-id
addresses :based-on-client-selection]])]}))
(rf/reg-event-fx :communities/toggle-share-all-addresses
toggle-share-all-addresses)
@@ -2,7 +2,6 @@
(:require [cljs.test :refer [deftest is testing]]
[legacy.status-im.mailserver.core :as mailserver]
matcher-combinators.test
[status-im.constants :as constants]
[status-im.contexts.chat.messenger.messages.link-preview.events :as link-preview.events]
[status-im.contexts.communities.events :as events]))
@@ -74,8 +73,8 @@
:position 1}}}
:communities {community-id {:share-all-addresses? true
:previous-share-all-addresses? true
:previous-permission-addresses #{"0x1"}
:selected-permission-addresses #{"0x1"}
:previous-permission-addresses #{"0x1" "0x2"}
:selected-permission-addresses #{"0x1" "0x2"}
:airdrop-address "0x1"}}}}
expected-db (update-in initial-db
[:db :communities community-id]
@@ -259,7 +258,7 @@
(-> effects :json-rpc/call first (select-keys [:method :params]))))))))
(deftest handle-community
(let [community {:id community-id}]
(let [community {:id community-id :clock 2}]
(testing "given a unjoined community"
(let [effects (events/handle-community {} [community])]
(is (match? community-id
@@ -284,29 +283,10 @@
[[:dispatch [:communities/initialize-permission-addresses community-id]]
[:dispatch [:chat.ui/spectate-community community-id]]]
(filter some? (:fx effects))))))
(testing "given a community with view channel permission"
(let [community (assoc community
:token-permissions
[["perm-id" {:type constants/community-token-permission-can-view-channel}]])
(testing "given a community with lower clock"
(let [effects (events/handle-community {:db {:communities {community-id {:clock 3}}}} [community])]
(is (nil? effects))))
(testing "given a community without clock"
(let [community (dissoc community :clock)
effects (events/handle-community {} [community])]
(is (match?
[[:dispatch [:communities/initialize-permission-addresses community-id]]
[:dispatch [:chat.ui/spectate-community community-id]]
[:dispatch [:communities/check-permissions-to-join-community community-id]]
[:dispatch
[:communities/check-all-community-channels-permissions community-id]]]
(filter some? (:fx effects))))))
(testing "given a community with post in channel permission"
(let [community (assoc community
:token-permissions
[["perm-id"
{:type constants/community-token-permission-can-view-and-post-channel}]])
effects (events/handle-community {} [community])]
(is (match?
[[:dispatch [:communities/initialize-permission-addresses community-id]]
[:dispatch [:chat.ui/spectate-community community-id]]
[:dispatch [:communities/check-permissions-to-join-community community-id]]
[:dispatch
[:communities/check-all-community-channels-permissions community-id]]]
(filter some? (:fx effects))))))))
(is (nil? effects))))))
@@ -1,37 +1,10 @@
(ns status-im.contexts.communities.overview.events
(:require
[legacy.status-im.data-store.communities :as data-store]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(rf/reg-event-fx :communities/check-all-community-channels-permissions-success
(fn [{:keys [db]} [community-id response]]
{:db (-> db
(assoc-in [:community-channels-permissions community-id]
(data-store/rpc->channel-permissions (:channels response)))
(assoc-in [:communities/channel-permissions-check community-id] false))}))
(rf/reg-event-fx :communities/check-all-community-channels-permissions-failed
(fn [{:keys [db]} [community-id]]
{:db (assoc-in db [:communities/channel-permissions-check community-id] false)}))
(rf/reg-event-fx :communities/check-all-community-channels-permissions
(fn [{:keys [db]} [community-id]]
(when (get-in db [:communities community-id])
{:db (assoc-in db [:communities/channel-permissions-check community-id] true)
:fx [[:json-rpc/call
[{:method "wakuext_checkAllCommunityChannelsPermissions"
:params [{:CommunityID community-id}]
:on-success [:communities/check-all-community-channels-permissions-success community-id]
:on-error (fn [error]
(rf/dispatch [:communities/check-all-community-channels-permissions-failed
community-id])
(log/error "failed to check channels permissions"
{:error error
:community-id community-id
:event
:communities/check-all-community-channels-permissions}))}]]]})))
(rf/reg-event-fx :communities/check-permissions-to-join-community-success
(fn [{:keys [db]} [community-id based-on-client-selection? result]]
@@ -48,15 +48,16 @@
:emoji emoji
:customization-color community-color
:mentions-count mentions-count
;; NOTE: this is a troolean, nil/true/false have different meaning
:locked? locked?
:notification notification}
channel-sheet-data {:selected-item (fn [] [quo/channel channel-options])
:content (fn [] sheet-content)}]
[rn/view {:key id}
[quo/channel
(merge channel-options
{:on-press on-press
:on-long-press #(rf/dispatch [:show-bottom-sheet channel-sheet-data])})]]))
(assoc channel-options
:on-press on-press
:on-long-press #(rf/dispatch [:show-bottom-sheet channel-sheet-data]))]]))
(defn- channel-list-component
[{:keys [on-category-layout community-id community-color on-first-channel-height-changed]}
@@ -253,8 +254,7 @@
:description-accessibility-label :community-description}])
(defn- community-content
[id]
(rf/dispatch [:communities/check-all-community-channels-permissions id])
[_]
(fn [id
{:keys [on-category-layout
collapsed?
+5 -4
View File
@@ -181,15 +181,16 @@
(chat.events/public-chat? current-chat)
(assoc :able-to-send-message? true)
(and (chat.events/community-chat? current-chat)
(get-in community [:chats (subs (:chat-id current-chat) 68) :can-post?]))
(assoc :able-to-send-message? true)
(and (chat.events/group-chat? current-chat)
(group-chats.db/member? my-public-key current-chat))
(assoc :able-to-send-message? true
:member? true)
(and (chat.events/community-chat? current-chat)
(get-in community [:chats (subs (:chat-id current-chat) 68) :can-post?]))
(assoc :able-to-send-message? true)
(not group-chat)
(assoc
:contact-request-state (get-in contacts [chat-id :contact-request-state])
+11 -40
View File
@@ -205,42 +205,13 @@
(sort-by :position)
(into []))))
(defn- get-chat-lock-state
"Returns the chat lock state.
- Nil: no lock (there are no permissions for the chat)
- True: locked (there are permissions and can-post? is false)
- False: unlocked (there are permissions and can-post? is true)"
[community-id channels-permissions {chat-id :id}]
(let [composite-key (keyword (str community-id chat-id))
permissions (get channels-permissions composite-key)
{view-only-satisfied? :satisfied?
view-only-permissions :permissions} (:view-only permissions)
{view-and-post-satisfied? :satisfied?
view-and-post-permissions :permissions} (:view-and-post permissions)
can-access? (or (and (seq view-only-permissions)
view-only-satisfied?)
(and (seq view-and-post-permissions)
view-and-post-satisfied?))]
(if (and (empty? view-only-permissions)
(empty? view-and-post-permissions))
nil
(not can-access?))))
(re-frame/reg-sub
:communities/community-channels-permissions
:<- [:communities/channels-permissions]
(fn [channel-permissions [_ community-id]]
(get channel-permissions community-id)))
(defn- reduce-over-categories
[community-id
categories
collapsed-categories
full-chats-data
channels-permissions]
full-chats-data]
(fn [acc
[_ {:keys [name categoryID position id emoji] :as chat}]]
[_ {:keys [name categoryID position id emoji can-post? token-gated?]}]]
(let [category-id (if (seq categoryID) categoryID constants/empty-category-id)
{:keys [unviewed-messages-count
unviewed-mentions-count
@@ -262,9 +233,11 @@
:unread-messages? (pos? unviewed-messages-count)
:position position
:mentions-count (or unviewed-mentions-count 0)
:locked? (get-chat-lock-state community-id
channels-permissions
chat)
:can-post? can-post?
;; NOTE: this is a troolean nil->no permissions, true->no access, false ->
;; has access
:locked? (when token-gated?
(not can-post?))
:id id}]
(update-in acc-with-category [category-id :chats] conj categorized-chat))))
@@ -273,17 +246,14 @@
(fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id])
(re-frame/subscribe [:chats/chats])
(re-frame/subscribe [:communities/collapsed-categories-for-community community-id])
(re-frame/subscribe [:communities/community-channels-permissions community-id])])
(fn [[{:keys [categories chats]} full-chats-data collapsed-categories
channels-permissions]
(re-frame/subscribe [:communities/collapsed-categories-for-community community-id])])
(fn [[{:keys [categories chats]} full-chats-data collapsed-categories]
[_ community-id]]
(let [reduce-fn (reduce-over-categories
community-id
categories
collapsed-categories
full-chats-data
channels-permissions)
full-chats-data)
categories-and-chats
(->> chats
(reduce reduce-fn {})
@@ -330,6 +300,7 @@
highest-permission-role (:type highest-role)
can-request-access? (and (boolean highest-permission-role) (not networks-not-supported?))]
{:can-request-access? can-request-access?
:checking? checking?
:highest-permission-role highest-permission-role
:networks-not-supported? networks-not-supported?
:no-member-permission? (and highest-permission-role
+78 -175
View File
@@ -84,26 +84,29 @@
:communities
{"0x1" {:id "0x1"
:chats {"0x1"
{:id "0x1"
:position 1
:name "chat1"
:muted? nil
:categoryID "1"
:can-post? true}
{:id "0x1"
:position 1
:name "chat1"
:muted? nil
:categoryID "1"
:token-gated? false
:can-post? true}
"0x2"
{:id "0x2"
:position 2
:name "chat2"
:muted? nil
:categoryID "1"
:can-post? false}
{:id "0x2"
:position 2
:name "chat2"
:muted? nil
:categoryID "1"
:token-gated? true
:can-post? false}
"0x3"
{:id "0x3"
:position 3
:name "chat3"
:muted? nil
:categoryID "2"
:can-post? true}}
{:id "0x3"
:position 3
:name "chat3"
:muted? nil
:categoryID "2"
:token-gated? true
:can-post? true}}
:categories {"1" {:id "1"
:position 2
:name "category1"}
@@ -112,141 +115,41 @@
:name "category2"}}
:joined true}})
(is
(= [["2"
{:id "2"
:name "category2"
:collapsed? nil
:position 1
:chats [{:name "chat3"
:position 3
:emoji nil
:muted? nil
:locked? nil
:id "0x3"
:unread-messages? false
:mentions-count 0}]}]
["1"
{:id "1"
:name "category1"
:collapsed? nil
:position 2
:chats [{:name "chat1"
:emoji nil
:position 1
:muted? nil
:locked? nil
:id "0x1"
:unread-messages? false
:mentions-count 0}
{:name "chat2"
:emoji nil
:position 2
:muted? nil
:locked? nil
:id "0x2"
:unread-messages? false
:mentions-count 0}]}]]
(rf/sub [sub-name "0x1"]))))
(testing "Channels with categories and token permissions"
(swap! rf-db/app-db assoc
:community-channels-permissions
{community-id
{(keyword (str community-id "0x100"))
{:view-only {:satisfied? false
:permissions {:token-permission-id-01 {:criteria [false]}}}
:view-and-post {:satisfied? true :permissions {}}}
(keyword (str community-id "0x200"))
{:view-only {:satisfied? true :permissions {}}
:view-and-post {:satisfied? true :permissions {}}}
(keyword (str community-id "0x300"))
{:view-only {:satisfied? false :permissions {}}
:view-and-post {:satisfied? true
:permissions {:token-permission-id-03 {:criteria [true]}}}}
(keyword (str community-id "0x400"))
{:view-only {:satisfied? true
:permissions {}}
:view-and-post {:satisfied? false
:permissions {:token-permission-id-04 {:criteria [false]}}}}}}
:communities
{community-id {:id community-id
:chats {"0x100" {:id "0x100"
:position 1
:name "chat1"
:muted? nil
:categoryID "1"
:can-post? false}
"0x200" {:id "0x200"
:position 2
:name "chat2"
:muted? nil
:categoryID "1"
:can-post? false}
"0x300" {:id "0x300"
:position 3
:name "chat3"
:muted? nil
:categoryID "2"
:can-post? true}
"0x400" {:id "0x400"
:position 4
:name "chat4"
:muted? nil
:categoryID "2"
:can-post? true}}
:categories {"1" {:id "1"
:position 2
:name "category1"}
"2" {:id "2"
:position 1
:name "category2"}}
:joined true}})
(is
(= [["2"
{:id "2"
:name "category2"
:collapsed? nil
:position 1
:chats [{:name "chat3"
:position 3
:emoji nil
:muted? nil
:locked? false
:id "0x300"
:unread-messages? false
:mentions-count 0}
{:name "chat4"
:position 4
:emoji nil
:muted? nil
:locked? true
:id "0x400"
:unread-messages? false
:mentions-count 0}]}]
["1"
{:id "1"
:name "category1"
:collapsed? nil
:position 2
:chats [{:name "chat1"
:emoji nil
:position 1
:muted? nil
:locked? true
:id "0x100"
:unread-messages? false
:mentions-count 0}
{:name "chat2"
:emoji nil
:position 2
:muted? nil
:locked? nil
:id "0x200"
:unread-messages? false
:mentions-count 0}]}]]
(rf/sub [sub-name "0x1"]))))
(match? [["2"
{:id "2"
:name "category2"
:collapsed? nil
:position 1
:chats [{:name "chat3"
:position 3
:emoji nil
:muted? nil
:locked? false
:id "0x3"
:unread-messages? false
:mentions-count 0}]}]
["1"
{:id "1"
:name "category1"
:collapsed? nil
:position 2
:chats [{:name "chat1"
:emoji nil
:position 1
:muted? nil
:locked? nil
:id "0x1"
:unread-messages? false
:mentions-count 0}
{:name "chat2"
:emoji nil
:position 2
:muted? nil
:locked? true
:id "0x2"
:unread-messages? false
:mentions-count 0}]}]]
(rf/sub [sub-name "0x1"]))))
(testing "Channels without categories"
(swap! rf-db/app-db assoc
:communities
@@ -274,7 +177,7 @@
:name "category2"}}
:joined true}})
(is
(=
(match?
[[constants/empty-category-id
{:name (i18n/label :t/none)
:collapsed? nil
@@ -323,27 +226,27 @@
{"0x10x1" {:unviewed-messages-count 1 :unviewed-mentions-count 2}
"0x10x2" {:unviewed-messages-count 0 :unviewed-mentions-count 0}})
(is
(= [["1"
{:name "category1"
:id "1"
:collapsed? nil
:chats [{:name "chat1"
:emoji nil
:position 1
:locked? nil
:id "0x1"
:muted? nil
:unread-messages? true
:mentions-count 2}
{:name "chat2"
:emoji nil
:position 2
:locked? nil
:muted? nil
:id "0x2"
:unread-messages? false
:mentions-count 0}]}]]
(rf/sub [sub-name "0x1"])))))
(match? [["1"
{:name "category1"
:id "1"
:collapsed? nil
:chats [{:name "chat1"
:emoji nil
:position 1
:locked? nil
:id "0x1"
:muted? nil
:unread-messages? true
:mentions-count 2}
{:name "chat2"
:emoji nil
:position 2
:locked? nil
:muted? nil
:id "0x2"
:unread-messages? false
:mentions-count 0}]}]]
(rf/sub [sub-name "0x1"])))))
(h/deftest-sub :communities/my-pending-requests-to-join
[sub-name]
-1
View File
@@ -139,7 +139,6 @@
(reg-root-key-sub :communities :communities)
(reg-root-key-sub :communities/create :communities/create)
(reg-root-key-sub :communities/create-channel :communities/create-channel)
(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/fetching-community :communities/fetching-community)
+3 -3
View File
@@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.174.8",
"commit-sha1": "8a3e71378f7208f75bd688c02b0ae5c43ca600f2",
"src-sha256": "10wn93xn6xnkg2d8slyygy9rfrwiargm49738bdjj1g4b81220bq"
"version": "release/0.174.x",
"commit-sha1": "469f429af096006c6bbffe6e3a4d58c59315e4f1",
"src-sha256": "1zzcpgh5mrkdr9vzxkzbq3k9njfxph1gv58kq4ybi7bac6gnby0y"
}