Hide community channels when hide channels option is enabled

This commit is contained in:
Ibrahem Khalil 2024-03-23 13:31:21 +02:00 committed by Andrea Maria Piana
parent 1948c11508
commit c86cdf9ac8
No known key found for this signature in database
3 changed files with 75 additions and 63 deletions

View File

@ -70,20 +70,21 @@
(defn <-rpc (defn <-rpc
[chat] [chat]
(-> chat (-> chat
(set/rename-keys {:id :chat-id (set/rename-keys {:id :chat-id
:communityId :community-id :communityId :community-id
:syncedFrom :synced-from :syncedFrom :synced-from
:syncedTo :synced-to :syncedTo :synced-to
:membershipUpdateEvents :membership-update-events :membershipUpdateEvents :membership-update-events
:deletedAtClockValue :deleted-at-clock-value :deletedAtClockValue :deleted-at-clock-value
:chatType :chat-type :chatType :chat-type
:unviewedMessagesCount :unviewed-messages-count :unviewedMessagesCount :unviewed-messages-count
:unviewedMentionsCount :unviewed-mentions-count :unviewedMentionsCount :unviewed-mentions-count
:lastMessage :last-message :lastMessage :last-message
:lastClockValue :last-clock-value :lastClockValue :last-clock-value
:invitationAdmin :invitation-admin :invitationAdmin :invitation-admin
:profile :profile-public-key :profile :profile-public-key
:muteTill :muted-till}) :muteTill :muted-till
:hideIfPermissionsNotMet :hide-if-permissions-not-met?})
rpc->type rpc->type
unmarshal-members unmarshal-members
(update :last-message #(when % (messages/<-rpc %))) (update :last-message #(when % (messages/<-rpc %)))
@ -92,38 +93,40 @@
(defn <-rpc-js (defn <-rpc-js
[^js chat] [^js chat]
(-> {:name (.-name chat) (-> {:name (.-name chat)
:description (.-description chat) :description (.-description chat)
:color (<-color (.-color chat)) :color (<-color (.-color chat))
:emoji (.-emoji chat) :emoji (.-emoji chat)
:timestamp (.-timestamp chat) :timestamp (.-timestamp chat)
:alias (.-alias chat) :alias (.-alias chat)
:muted (.-muted chat) :muted (.-muted chat)
:joined (.-joined chat) :joined (.-joined chat)
:muted-till (.-muteTill chat) :muted-till (.-muteTill chat)
:chat-id (.-id chat) :chat-id (.-id chat)
:community-id (.-communityId chat) :community-id (.-communityId chat)
:synced-from (.-syncedFrom chat) :synced-from (.-syncedFrom chat)
:synced-to (.-syncedTo chat) :synced-to (.-syncedTo chat)
:deleted-at-clock-value (.-deletedAtClockValue chat) :deleted-at-clock-value (.-deletedAtClockValue chat)
:chat-type (.-chatType chat) :chat-type (.-chatType chat)
:unviewed-messages-count (.-unviewedMessagesCount chat) :unviewed-messages-count (.-unviewedMessagesCount chat)
:unviewed-mentions-count (.-unviewedMentionsCount chat) :unviewed-mentions-count (.-unviewedMentionsCount chat)
:last-message {:content {:text (.-text chat) :last-message {:content {:text (.-text chat)
:parsed-text (types/js->clj (.-parsedText chat)) :parsed-text (types/js->clj (.-parsedText
:response-to (.-responseTo chat)} chat))
:content-type (.-contentType chat) :response-to (.-responseTo chat)}
:community-id (.-contentCommunityId chat) :content-type (.-contentType chat)
:outgoing (boolean (.-outgoingStatus chat)) :community-id (.-contentCommunityId chat)
:album-images-count (.-albumImagesCount chat) :outgoing (boolean (.-outgoingStatus chat))
:from (.-from chat) :album-images-count (.-albumImagesCount chat)
:deleted? (.-deleted chat) :from (.-from chat)
:deleted-for-me? (.-deletedForMe chat)} :deleted? (.-deleted chat)
:last-clock-value (.-lastClockValue chat) :deleted-for-me? (.-deletedForMe chat)}
:profile-public-key (.-profile chat) :last-clock-value (.-lastClockValue chat)
:highlight (.-highlight chat) :profile-public-key (.-profile chat)
:active (.-active chat) :highlight (.-highlight chat)
:members (types/js->clj (.-members chat))} :active (.-active chat)
:members (types/js->clj (.-members chat))
:hide-if-permissions-not-met (.-hideIfPermissionsNotMet chat)}
rpc->type rpc->type
unmarshal-members)) unmarshal-members))

View File

@ -27,10 +27,11 @@
(assoc acc (assoc acc
(name k) (name k)
(-> v (-> v
(assoc :token-gated? (:tokenGated v) (assoc :token-gated? (:tokenGated v)
:can-post? (:canPost v) :can-post? (:canPost v)
:can-view? (:canView v)) :can-view? (:canView v)
(dissoc :canPost :tokenGated :canView) :hide-if-permissions-not-met? (:hideIfPermissionsNotMet v))
(dissoc :canPost :tokenGated :canView :hideIfPermissionsNotMet)
(update :members walk/stringify-keys)))) (update :members walk/stringify-keys))))
{} {}
chats)) chats))

View File

@ -243,7 +243,8 @@
emoji emoji
can-view? can-view?
can-post? can-post?
token-gated?]}]] token-gated?
hide-if-permissions-not-met?]}]]
(let [category-id (if (seq categoryID) categoryID constants/empty-category-id) (let [category-id (if (seq categoryID) categoryID constants/empty-category-id)
{:keys [unviewed-messages-count {:keys [unviewed-messages-count
unviewed-mentions-count unviewed-mentions-count
@ -259,19 +260,21 @@
:collapsed? (get collapsed-categories :collapsed? (get collapsed-categories
category-id) category-id)
:chats []))) :chats [])))
categorized-chat {:name name locked? (when token-gated?
:emoji emoji (and (not can-view?)
:muted? muted (not can-post?)))
:unread-messages? (pos? unviewed-messages-count) categorized-chat {:name name
:position position :emoji emoji
:mentions-count (or unviewed-mentions-count 0) :muted? muted
:can-post? can-post? :unread-messages? (pos? unviewed-messages-count)
:position position
:mentions-count (or unviewed-mentions-count 0)
:can-post? can-post?
;; NOTE: this is a troolean nil->no permissions, true->no access, false ;; NOTE: this is a troolean nil->no permissions, true->no access, false
;; -> has access ;; -> has access
:locked? (when token-gated? :locked? locked?
(and (not can-view?) :hide-if-permissions-not-met? (and hide-if-permissions-not-met? locked?)
(not can-post?))) :id id}]
:id id}]
(update-in acc-with-category [category-id :chats] conj categorized-chat)))) (update-in acc-with-category [category-id :chats] conj categorized-chat))))
(re-frame/reg-sub (re-frame/reg-sub
@ -292,7 +295,12 @@
(reduce reduce-fn {}) (reduce reduce-fn {})
(sort-by (comp :position second)) (sort-by (comp :position second))
(map (fn [[k v]] (map (fn [[k v]]
[k (update v :chats #(sort-by :position %))])))] [k
(-> v
(update :chats #(sort-by :position %))
(update :chats
#(filter (comp not :hide-if-permissions-not-met?)
%)))])))]
categories-and-chats))) categories-and-chats)))
(re-frame/reg-sub (re-frame/reg-sub