fix Group Admin has no option to Edit a Group Chat (#21457)

This commit is contained in:
Parvesh Monu 2024-10-21 22:01:31 +05:30 committed by GitHub
parent 020d5cc1c1
commit fae4b34863
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 133 additions and 84 deletions

View File

@ -232,12 +232,11 @@
:sub-label nil :sub-label nil
:chevron? false}))) :chevron? false})))
;; TODO(OmarBasem): Requires design input.
(defn edit-name-image-entry (defn edit-name-image-entry
[] [chat-id]
(entry {:icon :i/edit (entry {:icon :i/edit
:label (i18n/label :t/edit-name-and-image) :label (i18n/label :t/edit-name-and-image)
:on-press #(js/alert "TODO: to be implemented, requires design input") :on-press #(rf/dispatch [:open-modal :screen/group-update chat-id])
:danger? false :danger? false
:accessibility-label :edit-name-and-image :accessibility-label :edit-name-and-image
:sub-label nil :sub-label nil
@ -359,7 +358,7 @@
(rf/dispatch [:chats-list/load-chat chat-id]) (rf/dispatch [:chats-list/load-chat chat-id])
(rf/dispatch [:pin-message/load-pin-messages chat-id]) (rf/dispatch [:pin-message/load-pin-messages chat-id])
(rf/dispatch [:hide-bottom-sheet]) (rf/dispatch [:hide-bottom-sheet])
(rf/dispatch [:navigate-to :group-details chat-id])) (rf/dispatch [:navigate-to :screen/group-details chat-id]))
:danger? false :danger? false
:accessibility-label :group-details :accessibility-label :group-details
:sub-label nil :sub-label nil
@ -369,18 +368,17 @@
[chat-id admin?] [chat-id admin?]
(entry {:icon :i/add-user (entry {:icon :i/add-user
:label (i18n/label (if admin? :t/manage-members :t/add-members)) :label (i18n/label (if admin? :t/manage-members :t/add-members))
:on-press #(rf/dispatch [:open-modal :group-add-manage-members chat-id]) :on-press #(rf/dispatch [:open-modal :screen/group-add-manage-members chat-id])
:danger? false :danger? false
:accessibility-label :manage-members :accessibility-label :manage-members
:sub-label nil :sub-label nil
:chevron? false})) :chevron? false}))
;; TODO(OmarBasem): to be implemented.
(defn edit-group-entry (defn edit-group-entry
[] [chat-id]
(entry {:icon :i/edit (entry {:icon :i/edit
:label (i18n/label :t/edit-name-and-image) :label (i18n/label :t/edit-name-and-image)
:on-press #(js/alert "TODO: to be implemented") :on-press #(rf/dispatch [:open-modal :screen/group-update chat-id])
:danger? false :danger? false
:accessibility-label :edit-group :accessibility-label :edit-group
:sub-label nil :sub-label nil
@ -426,8 +424,7 @@
(when inside-chat? (when inside-chat?
(add-manage-members-entry chat-id admin?)) (add-manage-members-entry chat-id admin?))
(when (and admin? inside-chat?) (when (and admin? inside-chat?)
(when config/show-not-implemented-features? (edit-group-entry chat-id))
(edit-group-entry)))
(when (and admin? inside-chat?) (when (and admin? inside-chat?)
(when config/show-not-implemented-features? (when config/show-not-implemented-features?
(group-privacy-entry)))])) (group-privacy-entry)))]))
@ -488,13 +485,12 @@
(chat-actions chat inside-chat? nil))) (chat-actions chat inside-chat? nil)))
(defn group-details-actions (defn group-details-actions
[{:keys [admins] :as group}] [{:keys [chat-id admins] :as group}]
(let [current-pub-key (rf/sub [:multiaccount/public-key]) (let [current-pub-key (rf/sub [:multiaccount/public-key])
admin? (get admins current-pub-key)] admin? (get admins current-pub-key)]
[quo/action-drawer [quo/action-drawer
[(when admin? [(when admin?
[(when config/show-not-implemented-features? [(edit-name-image-entry chat-id)])
(edit-name-image-entry))])
[(when config/show-not-implemented-features? [(when config/show-not-implemented-features?
(notifications-entry admin?))] (notifications-entry admin?))]
(destructive-actions group false)]])) (destructive-actions group false)]]))

View File

@ -9,7 +9,7 @@
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.contexts.chat.contacts.events :as contacts-store] [status-im.contexts.chat.contacts.events :as contacts-store]
status-im.contexts.chat.effects status-im.contexts.chat.effects
status-im.contexts.chat.group-create.events status-im.contexts.chat.group.events
[status-im.contexts.chat.messenger.composer.link-preview.events :as link-preview] [status-im.contexts.chat.messenger.composer.link-preview.events :as link-preview]
status-im.contexts.chat.messenger.messages.content.reactions.events status-im.contexts.chat.messenger.messages.content.reactions.events
[status-im.contexts.chat.messenger.messages.delete-message-for-me.events :as delete-for-me] [status-im.contexts.chat.messenger.messages.delete-message-for-me.events :as delete-for-me]

View File

@ -1,13 +1,11 @@
(ns status-im.contexts.chat.group-create.view (ns status-im.contexts.chat.group.common.group-edit
(:require [clojure.string :as string] (:require [quo.core :as quo]
[quo.core :as quo]
[quo.foundations.colors :as colors]
[quo.theme] [quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[status-im.common.avatar-picture-picker.view :as avatar-picture-picker] [status-im.common.avatar-picture-picker.view :as avatar-picture-picker]
[status-im.common.floating-button-page.view :as floating-button-page] [status-im.common.floating-button-page.view :as floating-button-page]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.contexts.chat.group-create.style :as style] [status-im.contexts.chat.group.common.style :as style]
[status-im.contexts.profile.utils :as profile.utils] [status-im.contexts.profile.utils :as profile.utils]
[utils.debounce :as debounce] [utils.debounce :as debounce]
utils.emojilib utils.emojilib
@ -41,35 +39,28 @@
:i/camera]])) :i/camera]]))
(defn view (defn view
[] [{:keys [default-group-name default-group-color default-group-image contacts
submit-button-label submit-event back-button-icon chat-id close on-success editing-group?]}]
(let [theme (quo.theme/use-theme) (let [theme (quo.theme/use-theme)
{window-width :width} (rn/get-window) {window-width :width} (rn/get-window)
profile (rf/sub [:profile/profile-with-image])
contacts (rf/sub [:selected-group-contacts])
contacts-count (count contacts) contacts-count (count contacts)
default-value (rn/use-memo [group-name set-group-name] (rn/use-state default-group-name)
(fn []
(let [contact-string (string/join ", "
(map
profile.utils/displayed-name
contacts))]
(subs contact-string
0
(min (count contact-string)
constants/max-group-chat-name-length))))
[])
[group-name set-group-name] (rn/use-state default-value)
[error-message [error-message
set-error-message] (rn/use-state nil) set-error-message] (rn/use-state nil)
group-name-empty? (not (and (string? group-name) (not-empty group-name))) group-name-empty? (not (and (string? group-name) (not-empty group-name)))
[group-color set-group-color] (rn/use-state (rand-nth colors/account-colors)) [group-color set-group-color] (rn/use-state default-group-color)
[group-image set-group-image] (rn/use-state nil) [group-image set-group-image] (rn/use-state default-group-image)
create-group-on-press (rn/use-callback #(debounce/throttle-and-dispatch on-submit (rn/use-callback #(debounce/throttle-and-dispatch
[:group-chat/create group-name group-color [submit-event
group-image] {:group-name group-name
:group-color group-color
:group-image (when (not= group-image
default-group-image)
group-image)
:chat-id chat-id
:on-success on-success}]
300) 300)
[group-name group-color group-image]) [group-name group-color group-image])
back-on-press (rn/use-callback #(rf/dispatch [:navigate-back]))
on-change-text (rn/use-callback on-change-text (rn/use-callback
(fn [text] (fn [text]
(if (boolean (re-find utils.emojilib/emoji-regex text)) (if (boolean (re-find utils.emojilib/emoji-regex text))
@ -77,7 +68,13 @@
{:check (i18n/label {:check (i18n/label
:t/emojis)})) :t/emojis)}))
(set-error-message nil)) (set-error-message nil))
(set-group-name text)))] (set-group-name text)))
disabled? (or group-name-empty?
error-message
(and editing-group?
(= group-name default-group-name)
(= group-color default-group-color)
(= group-image default-group-image)))]
[floating-button-page/view [floating-button-page/view
{:customization-color group-color {:customization-color group-color
:gradient-cover? true :gradient-cover? true
@ -85,13 +82,13 @@
:header [quo/page-nav :header [quo/page-nav
{:background :photo {:background :photo
:type :no-title :type :no-title
:icon-name :i/arrow-left :icon-name back-button-icon
:on-press back-on-press}] :on-press close}]
:footer [quo/button :footer [quo/button
{:customization-color group-color {:customization-color group-color
:disabled? (boolean (or group-name-empty? error-message)) :disabled? disabled?
:on-press create-group-on-press} :on-press on-submit}
(i18n/label :t/create-group-chat)]} submit-button-label]}
[:<> [:<>
[avatar [avatar
{:customization-color group-color {:customization-color group-color
@ -99,7 +96,7 @@
:set-group-image set-group-image}] :set-group-image set-group-image}]
[quo/title-input [quo/title-input
{:on-change-text on-change-text {:on-change-text on-change-text
:default-value default-value :default-value default-group-name
:container-style {:padding-horizontal 20 :padding-top 12 :padding-bottom (if error-message 0 16)} :container-style {:padding-horizontal 20 :padding-top 12 :padding-bottom (if error-message 0 16)}
:placeholder (i18n/label :t/name-your-group) :placeholder (i18n/label :t/name-your-group)
:max-length constants/max-group-chat-name-length}] :max-length constants/max-group-chat-name-length}]
@ -126,9 +123,9 @@
:padding-left (responsiveness/iphone-11-Pro-20-pixel-from-width :padding-left (responsiveness/iphone-11-Pro-20-pixel-from-width
window-width)}}]] window-width)}}]]
[quo/divider-label [quo/divider-label
(i18n/label :t/n-m-people {:n (inc contacts-count) :m constants/max-group-chat-participants})] (i18n/label :t/n-m-people {:n contacts-count :m constants/max-group-chat-participants})]
[rn/view {:style style/tags} [rn/view {:style style/tags}
(for [contact (conj contacts profile)] (for [contact contacts]
^{:key contact} ^{:key contact}
[quo/context-tag [quo/context-tag
{:container-style style/tag {:container-style style/tag

View File

@ -1,4 +1,4 @@
(ns status-im.contexts.chat.group-create.style (ns status-im.contexts.chat.group.common.style
(:require [quo.foundations.colors :as colors])) (:require [quo.foundations.colors :as colors]))
(def avatar {:width 88 :margin-top 12 :margin-left 20}) (def avatar {:width 88 :margin-top 12 :margin-left 20})

View File

@ -0,0 +1,27 @@
(ns status-im.contexts.chat.group.create.view
(:require
[clojure.string :as string]
[quo.foundations.colors :as colors]
[status-im.constants :as constants]
[status-im.contexts.chat.group.common.group-edit :as group-edit]
[status-im.contexts.profile.utils :as profile.utils]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn view
[{:keys [close]}]
(let [contacts (rf/sub [:selected-group-contacts])
contact-string (string/join ", " (map profile.utils/displayed-name contacts))
default-group-name (subs contact-string
0
(min (count contact-string) constants/max-group-chat-name-length))
profile (rf/sub [:profile/profile-with-image])
contacts (conj contacts profile)]
[group-edit/view
{:default-group-name default-group-name
:default-group-color (rand-nth colors/account-colors)
:contacts contacts
:submit-button-label (i18n/label :t/create-group-chat)
:submit-event :group-chat/create
:back-button-icon :i/arrow-left
:close close}]))

View File

@ -1,4 +1,4 @@
(ns status-im.contexts.chat.group-details.style (ns status-im.contexts.chat.group.details.style
(:require (:require
[quo.foundations.colors :as colors])) [quo.foundations.colors :as colors]))

View File

@ -1,4 +1,4 @@
(ns status-im.contexts.chat.group-details.view (ns status-im.contexts.chat.group.details.view
(:require (:require
[quo.core :as quo] [quo.core :as quo]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
@ -11,7 +11,7 @@
[status-im.common.contact-list.view :as contact-list] [status-im.common.contact-list.view :as contact-list]
[status-im.common.home.actions.view :as actions] [status-im.common.home.actions.view :as actions]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.contexts.chat.group-details.style :as style] [status-im.contexts.chat.group.details.style :as style]
[status-im.feature-flags :as ff] [status-im.feature-flags :as ff]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -54,7 +54,7 @@
(let [theme (quo.theme/use-theme) (let [theme (quo.theme/use-theme)
selected-participants (rf/sub [:group-chat/selected-participants]) selected-participants (rf/sub [:group-chat/selected-participants])
deselected-members (rf/sub [:group-chat/deselected-members]) deselected-members (rf/sub [:group-chat/deselected-members])
chat-id (rf/sub [:get-screen-params :group-add-manage-members]) chat-id (rf/sub [:get-screen-params :screen/group-add-manage-members])
{:keys [admins] :as group} (rf/sub [:chats/chat-by-id chat-id]) {:keys [admins] :as group} (rf/sub [:chats/chat-by-id chat-id])
current-pk (rf/sub [:multiaccount/public-key]) current-pk (rf/sub [:multiaccount/public-key])
admin? (get admins current-pk)] admin? (get admins current-pk)]
@ -123,9 +123,9 @@
[_] [_]
[rn/view {:style {:height 8}}]) [rn/view {:style {:height 8}}])
(defn group-details (defn view
[] []
(let [chat-id (rf/sub [:get-screen-params :group-details]) (let [chat-id (rf/sub [:get-screen-params :screen/group-details])
{:keys [admins chat-id chat-name color muted contacts image] {:keys [admins chat-id chat-name color muted contacts image]
:as group} (rf/sub [:chats/chat-by-id chat-id]) :as group} (rf/sub [:chats/chat-by-id chat-id])
members (rf/sub [:contacts/group-members-sections chat-id]) members (rf/sub [:contacts/group-members-sections chat-id])
@ -176,7 +176,8 @@
:icon :i/add-user :icon :i/add-user
:label (i18n/label (if admin? :t/manage-members :t/add-members)) :label (i18n/label (if admin? :t/manage-members :t/add-members))
:counter-value (count contacts) :counter-value (count contacts)
:on-press #(rf/dispatch [:open-modal :group-add-manage-members :on-press #(rf/dispatch [:open-modal
:screen/group-add-manage-members
chat-id])}]}] chat-id])}]}]
[rn/section-list [rn/section-list
{:key-fn :title {:key-fn :title

View File

@ -1,12 +1,12 @@
(ns status-im.contexts.chat.group-create.events (ns status-im.contexts.chat.group.events
(:require [clojure.string :as string] (:require [clojure.string :as string]
[legacy.status-im.data-store.chats :as data-store.chats]
[oops.core :as oops] [oops.core :as oops]
[re-frame.core :as rf] [re-frame.core :as rf]
[status-im.common.avatar-picture-picker.view :as avatar-picture-picker])) [status-im.common.avatar-picture-picker.view :as avatar-picture-picker]
[taoensso.timbre :as log]))
(rf/reg-event-fx :group-chat/create (rf/reg-event-fx :group-chat/create
(fn [{:keys [db]} [group-name color image]] (fn [{:keys [db]} [{:keys [group-name group-color group-image]}]]
(let [selected-contacts (:group/selected-contacts db)] (let [selected-contacts (:group/selected-contacts db)]
{:json-rpc/call [{:method "wakuext_createGroupChatWithMembers" {:json-rpc/call [{:method "wakuext_createGroupChatWithMembers"
:params [nil group-name (into [] selected-contacts)] :params [nil group-name (into [] selected-contacts)]
@ -19,23 +19,21 @@
(rf/dispatch [:group-chat/edit (rf/dispatch [:group-chat/edit
{:chat-id chat-id {:chat-id chat-id
:group-name group-name :group-name group-name
:color color :group-color group-color
:image image}])))}]}))) :group-image group-image}])))}]})))
(rf/reg-event-fx :group-chat/edit-success
(fn [{:keys [db]} [{:keys [chat-id name color image]}]]
(let [new-chat {:name name :color color :image image}]
{:db (update-in db [:chats chat-id] #(merge % new-chat))})))
(rf/reg-event-fx :group-chat/edit (rf/reg-event-fx :group-chat/edit
(fn [_ [{:keys [chat-id group-name color image]}]] (fn [_ [{:keys [chat-id group-name group-color group-image on-success]}]]
{:json-rpc/call [{:method "chat_editChat" {:json-rpc/call [{:method "chat_editChat"
:params ["" chat-id group-name (name color) :params ["" chat-id group-name (name group-color)
{:imagePath (when image (string/replace-first image #"file://" "")) {:imagePath (when group-image
(string/replace-first group-image #"file://" ""))
:x 0 :x 0
:y 0 :y 0
:width avatar-picture-picker/crop-size :width avatar-picture-picker/crop-size
:height avatar-picture-picker/crop-size}] :height avatar-picture-picker/crop-size}]
:js-response true :js-response true
:on-success #(rf/dispatch [:group-chat/edit-success :on-error #(log/error "failed to edit group" {:error %})
(data-store.chats/<-rpc-js %)])}]})) :on-success (fn [response]
(rf/dispatch [:chat-updated response true])
(when on-success (on-success)))}]}))

View File

@ -0,0 +1,23 @@
(ns status-im.contexts.chat.group.update.view
(:require
[status-im.contexts.chat.group.common.group-edit :as group-edit]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn view
[{:keys [close]}]
(let [chat-id (rf/sub [:get-screen-params :screen/group-update])
{:keys [chat-name color image]} (rf/sub [:chats/chat-by-id chat-id])
contacts (rf/sub [:contacts/contacts-by-chat chat-id])]
[group-edit/view
{:default-group-name chat-name
:default-group-color color
:default-group-image image
:contacts contacts
:submit-button-label (i18n/label :t/update-group-chat)
:submit-event :group-chat/edit
:back-button-icon :i/close
:chat-id chat-id
:close close
:on-success close
:editing-group? true}]))

View File

@ -149,7 +149,7 @@
:on-press (fn [] :on-press (fn []
(if one-contact-selected? (if one-contact-selected?
(rf/dispatch [:chat.ui/start-chat public-key]) (rf/dispatch [:chat.ui/start-chat public-key])
(rf/dispatch [:open-modal :group-create])))} (rf/dispatch [:open-modal :screen/group-create])))}
(if one-contact-selected? (if one-contact-selected?
(i18n/label :t/chat-with {:selected-user primary-name}) (i18n/label :t/chat-with {:selected-user primary-name})
(i18n/label :t/setup-group-chat))]])])) (i18n/label :t/setup-group-chat))]])]))

View File

@ -7,8 +7,9 @@
[status-im.common.lightbox.view :as lightbox] [status-im.common.lightbox.view :as lightbox]
[status-im.common.pdf-viewer.view :as pdf-viewer] [status-im.common.pdf-viewer.view :as pdf-viewer]
[status-im.config :as config] [status-im.config :as config]
[status-im.contexts.chat.group-create.view :as group-create] [status-im.contexts.chat.group.create.view :as group.create]
[status-im.contexts.chat.group-details.view :as group-details] [status-im.contexts.chat.group.details.view :as group.details]
[status-im.contexts.chat.group.update.view :as group.update]
[status-im.contexts.chat.home.add-new-contact.scan.scan-profile-qr-page :as scan-profile-qr-page] [status-im.contexts.chat.home.add-new-contact.scan.scan-profile-qr-page :as scan-profile-qr-page]
[status-im.contexts.chat.home.add-new-contact.views :as add-new-contact] [status-im.contexts.chat.home.add-new-contact.views :as add-new-contact]
[status-im.contexts.chat.home.new-chat.view :as new-chat] [status-im.contexts.chat.home.new-chat.view :as new-chat]
@ -171,17 +172,22 @@
:options {:sheet? true} :options {:sheet? true}
:component new-chat/view} :component new-chat/view}
{:name :group-add-manage-members {:name :screen/group-add-manage-members
:options {:sheet? true} :options {:sheet? true}
:component group-details/add-manage-members} :component group.details/add-manage-members}
{:name :group-create {:name :screen/group-create
:options {:sheet? true :options {:sheet? true
:skip-background? true} :skip-background? true}
:component group-create/view} :component group.create/view}
{:name :group-details {:name :screen/group-update
:component group-details/group-details} :options {:sheet? true
:skip-background? true}
:component group.update/view}
{:name :screen/group-details
:component group.details/view}
{:name :community-requests-to-join {:name :community-requests-to-join
:options {:sheet? true} :options {:sheet? true}

View File

@ -2646,6 +2646,7 @@
"untrustworthy": "Untrustworthy", "untrustworthy": "Untrustworthy",
"update": "Update", "update": "Update",
"update-account-name": "Update account name", "update-account-name": "Update account name",
"update-group-chat": "Update group chat",
"update-nickname-title": "Update nickname", "update-nickname-title": "Update nickname",
"update-to-listen-audio": "Update to latest version to listen to an audio message here!", "update-to-listen-audio": "Update to latest version to listen to an audio message here!",
"update-to-see-image": "Update to latest version to see a nice image here!", "update-to-see-image": "Update to latest version to see a nice image here!",