Allow owner/admin to delete messages of a community (#14366)

This commit is contained in:
frank 2022-12-02 20:13:02 +08:00 committed by GitHub
parent f3ad8beb6d
commit f7af7ca25d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 278 additions and 226 deletions

View File

@ -62,6 +62,7 @@
(-> c
(clojure.set/rename-keys {:canRequestAccess :can-request-access?
:canManageUsers :can-manage-users?
:canDeleteMessageForEveryone :can-delete-message-for-everyone?
:canJoin :can-join?
:requestedToJoinAt :requested-to-join-at
:isMember :is-member?})
@ -679,3 +680,38 @@
(fx/merge cofx
(navigation/pop-to-root-tab :shell-stack)
(navigation/navigate-to-nav2 :community community-id true)))
(fx/defn member-role-updated
{:events [:community.member/role-updated]}
[cofx response-js]
(fx/merge cofx
(bottom-sheet/hide-bottom-sheet)
(handle-response response-js)))
(fx/defn add-role-to-member
{:events [:community.member/add-role]}
[cofx community-id public-key role-id]
{::json-rpc/call [{:method "wakuext_addRoleToMember"
:params [{:communityId community-id
:user public-key
:role role-id}]
:on-success #(re-frame/dispatch [:community.member/role-updated %])
:on-error #(log/error "failed to add role to member"
{:error %
:community-id community-id
:public-key public-key
:role-id role-id})}]})
(fx/defn remove-role-from-member
{:events [:community.member/remove-role]}
[_ community-id public-key role-id]
{::json-rpc/call [{:method "wakuext_removeRoleFromMember"
:params [{:communityId community-id
:user public-key
:role role-id}]}
:on-success #(re-frame/dispatch [:community.member/role-updated %])
:on-error #(log/error "failed to remove role from member"
{:error %
:community-id community-id
:public-key public-key
:role-id role-id})]})

View File

@ -198,3 +198,7 @@
(def ^:const sticker-pack-status-owned 3)
(def ^:const delete-message-for-me-undo-time-limit-ms 4000)
(def ^:const community-member-role-all 1)
(def ^:const community-member-role-manage-users 2)
(def ^:const community-member-role-moderator 3)

View File

@ -16,7 +16,7 @@
(>evt [:bottom-sheet/hide])
(>evt event))
(defn member-sheet [first-name {:keys [public-key] :as member} community-id can-kick-users? can-manage-users?]
(defn member-sheet [first-name {:keys [public-key] :as member} community-id can-kick-users? can-manage-users? admin?]
[:<>
[quo/list-item
{:theme :accent
@ -39,12 +39,19 @@
[quo/list-item {:theme :negative
:icon :main-icons/cancel
:title (i18n/label :t/member-ban)
:on-press #(>evt [::communities/member-ban community-id public-key])}]])])
:on-press #(>evt [::communities/member-ban community-id public-key])}]])
(when admin?
[:<>
[quo/list-item {:theme :accent
:icon :main-icons/make-admin
:title (i18n/label :t/make-moderator)
:on-press #(>evt [:community.member/add-role community-id public-key constants/community-member-role-moderator])}]])])
(defn render-member [public-key _ _ {:keys [community-id
my-public-key
can-manage-users?
can-kick-users?]}]
can-kick-users?
admin?]}]
(let [member (<sub [:contacts/contact-by-identity public-key])
[first-name second-name] (<sub [:contacts/contact-two-names-by-identity public-key])]
[quo/list-item
@ -58,7 +65,7 @@
[quo/button {:on-press
#(>evt [:bottom-sheet/show-sheet
{:content (fn []
[member-sheet first-name member community-id can-kick-users? can-manage-users?])}])
[member-sheet first-name member community-id can-kick-users? can-manage-users? admin?])}])
:type :icon
:theme :icon
:accessibility-label :menu-option}
@ -91,7 +98,8 @@
(fn []
(let [my-public-key (<sub [:multiaccount/public-key])
{:keys [permissions
can-manage-users?]} (<sub [:communities/community community-id])
can-manage-users?
admin]} (<sub [:communities/community community-id])
sorted-members (<sub [:communities/sorted-community-members
community-id])]
[:<>
@ -106,7 +114,8 @@
:can-kick-users? (and can-manage-users?
(not= (:access permissions)
constants/community-no-membership-access))
:can-manage-users? can-manage-users?}
:can-manage-users? can-manage-users?
:admin? admin}
:key-fn identity
:render-fn render-member}]]))))

View File

@ -416,7 +416,7 @@
(re-frame/dispatch [::models.pin-message/show-pin-limit-modal chat-id]))
(re-frame/dispatch [::models.pin-message/send-pin-message (assoc message :pinned (not pinned))]))))
(defn on-long-press-fn [on-long-press {:keys [pinned message-pin-enabled outgoing edit-enabled show-input? community?] :as message} content]
(defn on-long-press-fn [on-long-press {:keys [pinned message-pin-enabled outgoing edit-enabled show-input? community? can-delete-message-for-everyone?] :as message} content]
(on-long-press
(concat
(when (and outgoing edit-enabled)
@ -453,7 +453,7 @@
:label (i18n/label :t/delete-for-me)
:icon :i/delete
:id :delete-for-me}]
(when (and outgoing config/delete-message-enabled?)
(when (and (or outgoing can-delete-message-for-everyone?) config/delete-message-enabled?)
[{:type :danger
:on-press (fn []
(when pinned (pin-message message))

View File

@ -81,7 +81,7 @@
idx
_
{:keys [group-chat public? community? current-public-key
chat-id show-input? message-pin-enabled edit-enabled in-pinned-view?]}]
chat-id show-input? message-pin-enabled edit-enabled in-pinned-view? can-delete-message-for-everyone?]}]
[rn/view {:style (when (and platform/android? (not in-pinned-view?)) {:scaleY -1})}
(if (= type :datemark)
[message-datemark/chat-datemark (:value message)]
@ -97,7 +97,8 @@
:current-public-key current-public-key
:show-input? show-input?
:message-pin-enabled message-pin-enabled
:edit-enabled edit-enabled)]))])
:edit-enabled edit-enabled
:can-delete-message-for-everyone? can-delete-message-for-everyone?)]))])
(defn on-viewable-items-changed [^js e]
(when @messages-list-ref
@ -124,7 +125,7 @@
(defn get-render-data [{:keys [group-chat chat-id public? community-id admins space-keeper show-input? edit-enabled in-pinned-view?]}]
(let [current-public-key (<sub [:multiaccount/public-key])
community (<sub [:communities/community community-id])
{:keys [can-delete-message-for-everyone?] :as community} (<sub [:communities/community community-id])
group-admin? (get admins current-public-key)
community-admin? (when community (community :admin))
message-pin-enabled (and (not public?)
@ -141,7 +142,8 @@
:show-input? show-input?
:message-pin-enabled message-pin-enabled
:edit-enabled edit-enabled
:in-pinned-view? in-pinned-view?}))
:in-pinned-view? in-pinned-view?
:can-delete-message-for-everyone? can-delete-message-for-everyone?}))
(defn messages-view [{:keys [chat
bottom-space

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.115.2",
"commit-sha1": "9227c631c30a88548cf04bed3b32938ef56f71aa",
"src-sha256": "1rkfiy9ka7qkka1a08mzs27f358dfvwgjjkcjd68207snis536iz"
"version": "v0.115.5",
"commit-sha1": "684e9654de4800df619ce593b5d331ebea9ed1a8",
"src-sha256": "0ci1s3w5jnf6sz2b6hn30gy14hp142gic006r6c3g5ln8y19wdbi"
}

View File

@ -860,6 +860,7 @@
"main-wallet": "Main Wallet",
"mainnet-network": "Main network",
"make-admin": "Make admin",
"make-moderator": "Make moderator",
"manage-keys-and-storage": "Manage keys and storage",
"mark-as-read": "Mark as read",
"mark-all-read": "Mark all read",