Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
472f1a949c | ||
|
|
43573d199b | ||
|
|
199381a4c7 | ||
|
|
6839b71524 | ||
|
|
3ea06b4495 | ||
|
|
ab722b3420 | ||
|
|
c057b3b4b0 | ||
|
|
3e00ccf7cc | ||
|
|
3d22ace169 | ||
|
|
3e1ffdea08 |
@@ -1,6 +1,6 @@
|
||||
(ns legacy.status-im.data-store.activities-test
|
||||
(:require
|
||||
[cljs.test :refer [deftest is testing]]
|
||||
[cljs.test :refer [deftest is]]
|
||||
[legacy.status-im.data-store.activities :as store]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.contexts.shell.activity-center.notification-types :as notification-types]))
|
||||
@@ -18,89 +18,6 @@
|
||||
:name chat-name
|
||||
:replyMessage {}})
|
||||
|
||||
(deftest <-rpc-test
|
||||
(testing "renames keys"
|
||||
(is (= {:name chat-name
|
||||
:chat-id chat-id
|
||||
:contact-verification-status constants/contact-verification-status-pending}
|
||||
(-> raw-notification
|
||||
store/<-rpc
|
||||
(dissoc :last-message :message :reply-message)))))
|
||||
|
||||
(testing "transforms messages from RPC response"
|
||||
(is
|
||||
(= {:last-message {:quoted-message nil
|
||||
:outgoing-status nil
|
||||
:command-parameters nil
|
||||
:link-previews []
|
||||
:content {:sticker nil
|
||||
:rtl? nil
|
||||
:ens-name nil
|
||||
:parsed-text nil
|
||||
:response-to nil
|
||||
:chat-id nil
|
||||
:image nil
|
||||
:line-count nil
|
||||
:links nil
|
||||
:text nil}
|
||||
:outgoing false}
|
||||
:message nil
|
||||
:reply-message {:quoted-message nil
|
||||
:outgoing-status nil
|
||||
:command-parameters nil
|
||||
:link-previews []
|
||||
:content {:sticker nil
|
||||
:rtl? nil
|
||||
:ens-name nil
|
||||
:parsed-text nil
|
||||
:response-to nil
|
||||
:chat-id nil
|
||||
:image nil
|
||||
:line-count nil
|
||||
:links nil
|
||||
:text nil}
|
||||
:outgoing false}}
|
||||
(-> raw-notification
|
||||
store/<-rpc
|
||||
(select-keys [:last-message :message :reply-message])))))
|
||||
|
||||
(testing "augments notification based on its type"
|
||||
(is (= {:chat-name chat-name
|
||||
:chat-type constants/private-group-chat-type
|
||||
:name chat-name}
|
||||
(-> raw-notification
|
||||
(assoc :type notification-types/reply)
|
||||
store/<-rpc
|
||||
(select-keys [:name :chat-type :chat-name :public? :group-chat]))))
|
||||
|
||||
(is (= {:chat-name chat-name
|
||||
:chat-type constants/private-group-chat-type
|
||||
:name chat-name}
|
||||
(-> raw-notification
|
||||
(assoc :type notification-types/mention)
|
||||
store/<-rpc
|
||||
(select-keys [:name :chat-type :chat-name :public? :group-chat]))))
|
||||
|
||||
(is (= {:chat-name chat-name
|
||||
:chat-type constants/private-group-chat-type
|
||||
:group-chat true
|
||||
:name chat-name
|
||||
:public? false}
|
||||
(-> raw-notification
|
||||
(assoc :type notification-types/private-group-chat)
|
||||
store/<-rpc
|
||||
(select-keys [:name :chat-type :chat-name :public? :group-chat]))))
|
||||
|
||||
(is (= {:chat-name chat-name
|
||||
:chat-type constants/one-to-one-chat-type
|
||||
:group-chat false
|
||||
:name chat-name
|
||||
:public? false}
|
||||
(-> raw-notification
|
||||
(assoc :type notification-types/one-to-one-chat)
|
||||
store/<-rpc
|
||||
(select-keys [:name :chat-type :chat-name :public? :group-chat]))))))
|
||||
|
||||
(deftest remove-pending-contact-request-test
|
||||
(is (true? (store/pending-contact-request?
|
||||
"contact-id"
|
||||
|
||||
@@ -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,14 @@
|
||||
:new :new?
|
||||
:albumImagesCount :album-images-count
|
||||
:displayName :display-name
|
||||
:linkPreviews :link-previews})
|
||||
:linkPreviews :link-previews
|
||||
:statusLinkPreviews :status-link-previews
|
||||
:bridgeMessage :bridge-message})
|
||||
(update :bridge-message
|
||||
set/rename-keys
|
||||
{:bridgeName :bridge-name
|
||||
:userName :user-name
|
||||
:userAvatar :user-avatar})
|
||||
(update :link-previews #(map <-link-preview-rpc %))
|
||||
(update :quoted-message
|
||||
set/rename-keys
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
:image nil
|
||||
:response-to "a"
|
||||
:links nil}
|
||||
:bridge-message nil
|
||||
:whisper-timestamp 1
|
||||
:contact-verification-state 1
|
||||
:contact-request-state 2
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
(def ^:const content-type-system-message-mutual-event-sent 15)
|
||||
(def ^:const content-type-system-message-mutual-event-accepted 16)
|
||||
(def ^:const content-type-system-message-mutual-event-removed 17)
|
||||
(def ^:const content-type-bridge-message 18)
|
||||
|
||||
;; Not implemented in status-go, only used for testing/ui work
|
||||
(def ^:const content-type-gif 100)
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
(ns status-im.contexts.chat.messenger.messages.content.view
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[legacy.status-im.ui.screens.chat.message.legacy-view :as old-message]
|
||||
[quo.core :as quo]
|
||||
[quo.foundations.colors :as colors]
|
||||
[quo.theme :as quo.theme]
|
||||
[react-native.core :as rn]
|
||||
[react-native.fast-image :as fast-image]
|
||||
[react-native.gesture :as gesture]
|
||||
[react-native.platform :as platform]
|
||||
[reagent.core :as reagent]
|
||||
@@ -113,6 +115,34 @@
|
||||
constants/content-type-system-message-mutual-event-sent
|
||||
[system-message-contact-request message-data :contact-request])))
|
||||
|
||||
(defn bridge-message-content
|
||||
[{:keys [bridge-message timestamp]}]
|
||||
(let [{:keys [user-avatar user-name
|
||||
bridge-name content]} bridge-message
|
||||
user-name (when (string? user-name)
|
||||
(-> user-name
|
||||
(string/replace "<b>" "")
|
||||
(string/replace "</b>" "")))]
|
||||
[rn/view
|
||||
{:style {:flex-direction :row
|
||||
:padding-horizontal 12
|
||||
:padding-top 4}}
|
||||
[fast-image/fast-image
|
||||
{:source {:uri user-avatar}
|
||||
:style {:width 32
|
||||
:margin-top 4
|
||||
:border-radius 16
|
||||
:height 32}}]
|
||||
[rn/view {:margin-left 8 :flex 1}
|
||||
[quo/author
|
||||
{:primary-name (str user-name)
|
||||
:short-chat-key (str "Bridged from " bridge-name)
|
||||
:time-str (datetime/timestamp->time timestamp)}]
|
||||
[quo/text
|
||||
{:size :paragraph-1
|
||||
:style {:line-height 22.75}}
|
||||
content]]]))
|
||||
|
||||
(declare on-long-press)
|
||||
|
||||
(defn- user-message-content-internal
|
||||
@@ -284,6 +314,9 @@
|
||||
keyboard-shown?))
|
||||
context]
|
||||
|
||||
(= content-type constants/content-type-bridge-message)
|
||||
[bridge-message-content message-data]
|
||||
|
||||
:else
|
||||
[user-message-content
|
||||
{:message-data message-data
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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,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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user