Allow non admin to add members to group chats #20396 (#20428)

This commit is contained in:
flexsurfer 2024-06-21 15:49:20 +02:00 committed by GitHub
parent 5ee5d70567
commit f509d132f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 41 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]}]
(let [current-pk (rf/sub [:multiaccount/public-key])
{:keys [contacts]} group
[{:keys [public-key] :as item} _ _ {:keys [group admin? current-pk]}]
(let [{: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 [theme (quo.theme/use-theme)
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])
current-pk (rf/sub [:multiaccount/public-key])
admin? (get admins current-pk)]
[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,9 @@
: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?
:current-pk current-pk}
:render-fn add-member-contact-item-render}]
[rn/view {:style (style/bottom-container 30 theme)}
[quo/button
@ -159,17 +169,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