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

View File

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

View File

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