Limit number of participants in group chat to 10
This commit is contained in:
parent
9d21cf143e
commit
a52f3d4d08
|
@ -3,13 +3,16 @@
|
||||||
[status-im.ui.components.react :as react]
|
[status-im.ui.components.react :as react]
|
||||||
[status-im.utils.platform :as platform]))
|
[status-im.utils.platform :as platform]))
|
||||||
|
|
||||||
(defn- checkbox-generic [{:keys [on-value-change checked? accessibility-label style] :or {accessibility-label :checkbox}} plain?]
|
(defn- checkbox-generic [{:keys [on-value-change checked? accessibility-label disabled? style] :or {accessibility-label :checkbox}} plain?]
|
||||||
(let [icon-check-container (if plain? #() styles/icon-check-container)
|
(let [icon-check-container (if plain? #() styles/icon-check-container)
|
||||||
check-icon (if plain? styles/plain-check-icon styles/check-icon)]
|
check-icon (if plain? styles/plain-check-icon styles/check-icon)]
|
||||||
(if platform/android?
|
(if (or platform/android?
|
||||||
|
platform/desktop?)
|
||||||
[react/view (merge styles/wrapper style)
|
[react/view (merge styles/wrapper style)
|
||||||
[react/check-box {:on-value-change on-value-change
|
[react/check-box {:on-value-change on-value-change
|
||||||
:value checked?
|
:value checked?
|
||||||
|
:disabled (and (not checked?)
|
||||||
|
disabled?)
|
||||||
:accessibility-label accessibility-label}]]
|
:accessibility-label accessibility-label}]]
|
||||||
[react/touchable-highlight (merge {:style (merge styles/wrapper style)
|
[react/touchable-highlight (merge {:style (merge styles/wrapper style)
|
||||||
:accessibility-label accessibility-label}
|
:accessibility-label accessibility-label}
|
||||||
|
|
|
@ -58,11 +58,12 @@
|
||||||
[react/view styles/more-btn
|
[react/view styles/more-btn
|
||||||
[vector-icons/icon :icons/options {:accessibility-label :options}]]]]))]])
|
[vector-icons/icon :icons/options {:accessibility-label :options}]]]]))]])
|
||||||
|
|
||||||
(views/defview toggle-contact-view [{:keys [public-key] :as contact} selected-key on-toggle-handler]
|
(views/defview toggle-contact-view [{:keys [public-key] :as contact} selected-key on-toggle-handler disabled?]
|
||||||
(views/letsubs [checked [selected-key public-key]]
|
(views/letsubs [checked [selected-key public-key]]
|
||||||
[react/view {:accessibility-label :contact-item}
|
[react/view {:accessibility-label :contact-item}
|
||||||
[list/list-item-with-checkbox
|
[list/list-item-with-checkbox
|
||||||
{:checked? checked
|
{:checked? checked
|
||||||
|
:disabled? disabled?
|
||||||
:on-value-change #(on-toggle-handler checked public-key)
|
:on-value-change #(on-toggle-handler checked public-key)
|
||||||
:plain-checkbox? true}
|
:plain-checkbox? true}
|
||||||
[react/view styles/contact-container
|
[react/view styles/contact-container
|
||||||
|
|
|
@ -12,19 +12,44 @@
|
||||||
[status-im.ui.components.toolbar.view :as toolbar]
|
[status-im.ui.components.toolbar.view :as toolbar]
|
||||||
[status-im.ui.screens.group.styles :as styles]))
|
[status-im.ui.screens.group.styles :as styles]))
|
||||||
|
|
||||||
(defn- on-toggle [checked? public-key]
|
(defn- on-toggle [allow-new-users? checked? public-key]
|
||||||
(let [action (if checked? :deselect-contact :select-contact)]
|
(cond
|
||||||
(re-frame/dispatch [action public-key])))
|
|
||||||
|
|
||||||
(defn- on-toggle-participant [checked? public-key]
|
checked?
|
||||||
(let [action (if checked? :deselect-participant :select-participant)]
|
(re-frame/dispatch [:deselect-contact public-key allow-new-users?])
|
||||||
(re-frame/dispatch [action public-key])))
|
|
||||||
|
|
||||||
(defn- group-toggle-contact [contact]
|
;; Only allow new users if not reached the maximum
|
||||||
[toggle-contact-view contact :is-contact-selected? on-toggle])
|
(and (not checked?)
|
||||||
|
allow-new-users?)
|
||||||
|
(re-frame/dispatch [:select-contact public-key allow-new-users?])))
|
||||||
|
|
||||||
(defn- group-toggle-participant [contact]
|
(defn- on-toggle-participant [allow-new-users? checked? public-key]
|
||||||
[toggle-contact-view contact :is-participant-selected? on-toggle-participant])
|
(cond
|
||||||
|
|
||||||
|
checked?
|
||||||
|
(re-frame/dispatch [:deselect-participant public-key allow-new-users?])
|
||||||
|
|
||||||
|
;; Only allow new users if not reached the maximum
|
||||||
|
(and (not checked?)
|
||||||
|
allow-new-users?)
|
||||||
|
(re-frame/dispatch [:select-participant public-key allow-new-users?])))
|
||||||
|
|
||||||
|
(defn- group-toggle-contact [allow-new-users? contact]
|
||||||
|
[toggle-contact-view
|
||||||
|
contact
|
||||||
|
:is-contact-selected?
|
||||||
|
(partial on-toggle allow-new-users?)
|
||||||
|
(and (not (:is-contact-selected? contact))
|
||||||
|
(not allow-new-users?))])
|
||||||
|
|
||||||
|
(defn- group-toggle-participant [allow-new-users? contact]
|
||||||
|
[toggle-contact-view
|
||||||
|
contact
|
||||||
|
:is-participant-selected?
|
||||||
|
(partial on-toggle-participant allow-new-users?)
|
||||||
|
;; Disable if not-checked and we don't allow new users
|
||||||
|
(and (not (:is-participant-selected? contact))
|
||||||
|
(not allow-new-users?))])
|
||||||
|
|
||||||
(defn- handle-invite-friends-pressed []
|
(defn- handle-invite-friends-pressed []
|
||||||
(if utils.platform/desktop?
|
(if utils.platform/desktop?
|
||||||
|
@ -61,6 +86,15 @@
|
||||||
(i18n/label :t/group-chat-no-contacts)]
|
(i18n/label :t/group-chat-no-contacts)]
|
||||||
[buttons/secondary-button {:on-press handle-invite-friends-pressed} (i18n/label :t/invite-friends)]])
|
[buttons/secondary-button {:on-press handle-invite-friends-pressed} (i18n/label :t/invite-friends)]])
|
||||||
|
|
||||||
|
(def max-participants 10)
|
||||||
|
|
||||||
|
(defn number-of-participants-disclaimer [number-of-participants-available]
|
||||||
|
[react/view {:style styles/number-of-participants-disclaimer}
|
||||||
|
[react/text (if (> number-of-participants-available
|
||||||
|
0)
|
||||||
|
(i18n/label-pluralize number-of-participants-available :t/available-participants)
|
||||||
|
(i18n/label :t/no-more-participants-available))]])
|
||||||
|
|
||||||
;; Start group chat
|
;; Start group chat
|
||||||
(defview contact-toggle-list []
|
(defview contact-toggle-list []
|
||||||
(letsubs [contacts [:contacts/all-added-people-contacts]
|
(letsubs [contacts [:contacts/all-added-people-contacts]
|
||||||
|
@ -71,15 +105,17 @@
|
||||||
:label (i18n/label :t/next)
|
:label (i18n/label :t/next)
|
||||||
:count (pos? selected-contacts-count)}
|
:count (pos? selected-contacts-count)}
|
||||||
(i18n/label :t/group-chat)]
|
(i18n/label :t/group-chat)]
|
||||||
|
[number-of-participants-disclaimer (- (dec max-participants) selected-contacts-count)]
|
||||||
(if (seq contacts)
|
(if (seq contacts)
|
||||||
[toggle-list contacts group-toggle-contact]
|
[toggle-list contacts (partial group-toggle-contact (< selected-contacts-count (dec max-participants)))]
|
||||||
[no-contacts])]))
|
[no-contacts])]))
|
||||||
|
|
||||||
;; Add participants to existing group chat
|
;; Add participants to existing group chat
|
||||||
(defview add-participants-toggle-list []
|
(defview add-participants-toggle-list []
|
||||||
(letsubs [contacts [:contacts/all-contacts-not-in-current-chat]
|
(letsubs [contacts [:contacts/all-contacts-not-in-current-chat]
|
||||||
{:keys [name]} [:chats/current-chat]
|
{:keys [name] :as current-chat} [:chats/current-chat]
|
||||||
selected-contacts-count [:selected-participants-count]]
|
selected-contacts-count [:selected-participants-count]]
|
||||||
|
(let [current-participants-count (count (:contacts current-chat))]
|
||||||
[react/keyboard-avoiding-view {:style styles/group-container}
|
[react/keyboard-avoiding-view {:style styles/group-container}
|
||||||
[status-bar]
|
[status-bar]
|
||||||
[toggle-list-toolbar {:count selected-contacts-count
|
[toggle-list-toolbar {:count selected-contacts-count
|
||||||
|
@ -88,5 +124,8 @@
|
||||||
(re-frame/dispatch [:navigate-back]))
|
(re-frame/dispatch [:navigate-back]))
|
||||||
:label (i18n/label :t/add)}
|
:label (i18n/label :t/add)}
|
||||||
name]
|
name]
|
||||||
|
|
||||||
|
[number-of-participants-disclaimer (- max-participants current-participants-count)]
|
||||||
(when (seq contacts)
|
(when (seq contacts)
|
||||||
[toggle-list contacts group-toggle-participant])]))
|
[toggle-list contacts (partial group-toggle-participant (< (+ current-participants-count
|
||||||
|
selected-contacts-count) max-participants))])])))
|
||||||
|
|
|
@ -23,3 +23,10 @@
|
||||||
:margin-horizontal 50
|
:margin-horizontal 50
|
||||||
:text-align :center
|
:text-align :center
|
||||||
:color colors/gray})
|
:color colors/gray})
|
||||||
|
|
||||||
|
(def number-of-participants-disclaimer
|
||||||
|
{:margin-top 20
|
||||||
|
:margin-bottom 5
|
||||||
|
:font-size 12
|
||||||
|
:margin-horizontal 17})
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,11 @@
|
||||||
"name-placeholder": "Display name",
|
"name-placeholder": "Display name",
|
||||||
"find": "Find",
|
"find": "Find",
|
||||||
"close-app-title": "Warning!",
|
"close-app-title": "Warning!",
|
||||||
|
"available-participants": {
|
||||||
|
"one": "You can select one more participant",
|
||||||
|
"other": "You can select {{count}} more participants"
|
||||||
|
},
|
||||||
|
"no-more-participants-available": "You can't add anymore participants",
|
||||||
"group-chat-created": "*{{member}}* created the group *{{name}}*",
|
"group-chat-created": "*{{member}}* created the group *{{name}}*",
|
||||||
"group-chat-admin": "Admin",
|
"group-chat-admin": "Admin",
|
||||||
"group-chat-name-changed": "*{{member}}* changed the group's name to *{{name}}*",
|
"group-chat-name-changed": "*{{member}}* changed the group's name to *{{name}}*",
|
||||||
|
|
Loading…
Reference in New Issue