Allow non admin to add members to group chats #20396

This commit is contained in:
andrey 2024-06-11 09:57:42 +02:00
parent 0d2869bfe0
commit c7eda091b9
No known key found for this signature in database
GPG Key ID: C20F2FDE9A98BA61
2 changed files with 36 additions and 39 deletions

View File

@ -365,20 +365,10 @@
:sub-label nil
:chevron? false}))
(defn add-members-entry
[chat-id]
(defn add-manage-members-entry
[chat-id admin?]
(entry {:icon :i/add-user
:label (i18n/label :t/add-members)
:on-press #(rf/dispatch [:open-modal :group-add-manage-members chat-id])
:danger? false
:accessibility-label :add-members
:sub-label nil
:chevron? false}))
(defn manage-members-entry
[chat-id]
(entry {:icon :i/add-user
:label (i18n/label :t/manage-members)
:label (i18n/label (if admin? :t/manage-members :t/add-members))
:on-press #(rf/dispatch [:open-modal :group-add-manage-members chat-id])
:danger? false
:accessibility-label :manage-members
@ -433,8 +423,7 @@
admin? (get admins current-pub-key)]
[(group-details-entry chat-id)
(when inside-chat?
(when admin?
(manage-members-entry chat-id)))
(add-manage-members-entry chat-id admin?))
(when (and admin? inside-chat?)
(when config/show-not-implemented-features?
(edit-group-entry)))

View File

@ -27,29 +27,37 @@
(rf/dispatch [:deselect-member public-key true]))))
(defn add-member-contact-item-render
[{:keys [public-key] :as item} _ _ {:keys [group]}]
[{:keys [public-key] :as item} _ _ {:keys [group admin?]}]
(let [current-pk (rf/sub [:multiaccount/public-key])
{:keys [contacts]} group
member? (contains? contacts public-key)
checked? (reagent/atom member?)]
(fn []
(let [on-toggle #(group-chat-member-toggle member? (swap! checked? not) public-key)]
(if (or (= current-pk public-key) (and (not admin?) member?))
(fn []
[contact-list-item/contact-list-item
(when (not= current-pk public-key)
{:disabled? true
:accessory {:disabled? true
:type :checkbox
:checked? @checked?}}
item])
(fn []
(let [on-toggle #(group-chat-member-toggle member? (swap! checked? not) public-key)]
[contact-list-item/contact-list-item
{:on-press on-toggle
:allow-multiple-presses? true
:accessory {:type :checkbox
:checked? @checked?
:on-check on-toggle}})
item]))))
:on-check on-toggle}}
item])))))
(defn add-manage-members
[{:keys [scroll-enabled? on-scroll]}]
(let [selected-participants (rf/sub [:group-chat/selected-participants])
deselected-members (rf/sub [:group-chat/deselected-members])
chat-id (rf/sub [:get-screen-params :group-add-manage-members])
group (rf/sub [:chats/chat-by-id chat-id])
theme (quo.theme/use-theme)]
(let [selected-participants (rf/sub [:group-chat/selected-participants])
deselected-members (rf/sub [:group-chat/deselected-members])
chat-id (rf/sub [:get-screen-params :group-add-manage-members])
{:keys [admins] :as group} (rf/sub [:chats/chat-by-id chat-id])
theme (quo.theme/use-theme)
admin? (get admins (rf/sub [:multiaccount/public-key]))]
[rn/view {:flex 1 :margin-top 20}
[rn/touchable-opacity
{:on-press #(rf/dispatch [:navigate-back])
@ -60,7 +68,7 @@
{:size :heading-1
:weight :semi-bold
:style {:margin-left 20}}
(i18n/label :t/manage-members)]
(i18n/label (if admin? :t/manage-members :t/add-members))]
[gesture/section-list
{:key-fn :title
:scroll-enabled @scroll-enabled?
@ -70,7 +78,8 @@
:render-section-header-fn contact-list/contacts-section-header
:render-section-footer-fn contact-list/contacts-section-footer
:content-container-style {:padding-bottom 20}
:render-data {:group group}
:render-data {:group group
:admin? admin?}
:render-fn add-member-contact-item-render}]
[rn/view {:style (style/bottom-container 30 theme)}
[quo/button
@ -159,17 +168,16 @@
:on-press #(rf/dispatch [:chat.ui/mute chat-id (not muted)
(when-not muted
constants/mute-till-unmuted)])}
(when admin?
{:accessibility-label :manage-members
:customization-color color
:icon :i/add-user
:label (i18n/label :t/manage-members)
:counter-value (count contacts)
:on-press (fn []
(rf/dispatch [:group/clear-added-participants])
(rf/dispatch [:group/clear-removed-members])
(rf/dispatch [:open-modal :group-add-manage-members
chat-id]))})]}]
{:accessibility-label :manage-members
:customization-color color
:icon :i/add-user
:label (i18n/label (if admin? :t/manage-members :t/add-members))
:counter-value (count contacts)
:on-press (fn []
(rf/dispatch [:group/clear-added-participants])
(rf/dispatch [:group/clear-removed-members])
(rf/dispatch [:open-modal :group-add-manage-members
chat-id]))}]}]
[rn/section-list
{:key-fn :title
:sticky-section-headers-enabled false