feat: support community that all members allowed to pin (#15197)

This commit is contained in:
yqrashawn 2023-03-02 18:43:21 +08:00 committed by GitHub
parent f731f75fca
commit 4190dfd26b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 34 deletions

View File

@ -71,7 +71,11 @@
:canDeleteMessageForEveryone :can-delete-message-for-everyone? :canDeleteMessageForEveryone :can-delete-message-for-everyone?
:canJoin :can-join? :canJoin :can-join?
:requestedToJoinAt :requested-to-join-at :requestedToJoinAt :requested-to-join-at
:isMember :is-member?}) :isMember :is-member?
:adminSettings :admin-settings})
(update :admin-settings
set/rename-keys
{:pinMessageAllMembersEnabled :pin-message-all-members-enabled?})
(update :members walk/stringify-keys) (update :members walk/stringify-keys)
(update :chats <-chats-rpc) (update :chats <-chats-rpc)
(update :categories <-categories-rpc))) (update :categories <-categories-rpc)))

View File

@ -72,16 +72,20 @@
"compute data used to render message list, including pinned message list and message list in chats" "compute data used to render message list, including pinned message list and message list in chats"
[{:keys [group-chat chat-id public? community-id admins space-keeper show-input? edit-enabled [{:keys [group-chat chat-id public? community-id admins space-keeper show-input? edit-enabled
in-pinned-view?]}] in-pinned-view?]}]
(let [current-public-key (rf/sub [:multiaccount/public-key]) (let [current-public-key (rf/sub [:multiaccount/public-key])
{:keys [can-delete-message-for-everyone?] :as community} (rf/sub [:communities/community {:keys [can-delete-message-for-everyone?
community-id]) admin-settings]
group-admin? (get admins current-public-key) :as community} (rf/sub [:communities/community
community-admin? (when community (community :admin)) community-id])
message-pin-enabled (and (not public?) {:keys [pin-message-all-members-enabled?]} admin-settings
(or (not group-chat) group-admin? (get admins current-public-key)
(and group-chat community-admin? (when community (community :admin))
(or group-admin? message-pin-enabled (and (not public?)
community-admin?))))] (or (not group-chat)
(and group-chat
(or group-admin?
pin-message-all-members-enabled?
community-admin?))))]
{:group-chat group-chat {:group-chat group-chat
:group-admin? group-admin? :group-admin? group-admin?
:public? public? :public? public?

View File

@ -3,8 +3,8 @@
[status-im.chat.models.reactions :as models.reactions] [status-im.chat.models.reactions :as models.reactions]
[status-im2.constants :as constants] [status-im2.constants :as constants]
[status-im2.contexts.chat.messages.list.events :as models.message-list] [status-im2.contexts.chat.messages.list.events :as models.message-list]
[utils.i18n :as i18n] [utils.datetime :as datetime]
[utils.datetime :as datetime])) [utils.i18n :as i18n]))
(defn intersperse-datemark (defn intersperse-datemark
"Reduce step which expects the input list of messages to be sorted by clock value. "Reduce step which expects the input list of messages to be sorted by clock value.
@ -192,7 +192,6 @@
(sort-by :pinned-at sort-pinned pin-messages-vals)))) (sort-by :pinned-at sort-pinned pin-messages-vals))))
(re-frame/reg-sub (re-frame/reg-sub
:chats/pin-modal :chats/pin-modal
:<- [:messages/pin-modal] :<- [:messages/pin-modal]
@ -220,32 +219,12 @@
(fn [pagination-info [_ chat-id]] (fn [pagination-info [_ chat-id]]
(get-in pagination-info [chat-id :loading-messages?]))) (get-in pagination-info [chat-id :loading-messages?])))
(re-frame/reg-sub
:chats/loading-pin-messages?
:<- [:messages/pagination-info]
(fn [pagination-info [_ chat-id]]
(get-in pagination-info [chat-id :loading-pin-messages?])))
(re-frame/reg-sub (re-frame/reg-sub
:chats/message-list :chats/message-list
:<- [:messages/message-lists] :<- [:messages/message-lists]
(fn [message-lists [_ chat-id]] (fn [message-lists [_ chat-id]]
(get message-lists chat-id))) (get message-lists chat-id)))
(re-frame/reg-sub
:chats/pin-message-list
:<- [:messages/pin-message-lists]
(fn [pin-message-lists [_ chat-id]]
(get pin-message-lists chat-id)))
(re-frame/reg-sub
:chats/chat-no-messages?
(fn [[_ chat-id] _]
(re-frame/subscribe [:chats/chat-messages chat-id]))
(fn [messages]
(empty? messages)))
(re-frame/reg-sub (re-frame/reg-sub
:chats/raw-chat-messages-stream :chats/raw-chat-messages-stream
(fn [[_ chat-id] _] (fn [[_ chat-id] _]