[18979] Implement context action Invite contacts to community (#18989)

This commit is contained in:
Ibrahem Khalil 2024-04-12 00:12:02 +02:00 committed by GitHub
parent cfc43be3cc
commit 2614131426
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 432 additions and 102 deletions

View File

@ -4,6 +4,7 @@
[legacy.status-im.bottom-sheet.events :as bottom-sheet]
legacy.status-im.communities.e2e
[re-frame.core :as re-frame]
[status-im.contexts.shell.activity-center.events :as activity-center]
[status-im.navigation.events :as navigation]
[taoensso.timbre :as log]
[utils.re-frame :as rf]))
@ -22,60 +23,10 @@
{}
requests))
(defn- fetch-community-id-input
[{:keys [db]}]
(:communities/community-id-input db))
(rf/defn handle-response
[_ response-js]
{:dispatch [:sanitize-messages-and-process-response response-js]})
(rf/defn invite-users
{:events [::invite-people-confirmation-pressed]}
[cofx user-pk contacts]
(let [community-id (fetch-community-id-input cofx)
pks (if (seq user-pk)
(conj contacts user-pk)
contacts)]
(when (seq pks)
{:json-rpc/call [{:method "wakuext_inviteUsersToCommunity"
:params [{:communityId community-id
:users pks}]
:js-response true
:on-success #(re-frame/dispatch [::people-invited %])
:on-error #(do
(log/error "failed to invite-user community" %)
(re-frame/dispatch [::failed-to-invite-people %]))}]})))
(rf/defn share-community
{:events [::share-community-confirmation-pressed]}
[cofx user-pk contacts]
(let [community-id (fetch-community-id-input cofx)
pks (if (seq user-pk)
(conj contacts user-pk)
contacts)]
(when (seq pks)
{:json-rpc/call [{:method "wakuext_shareCommunity"
:params [{:communityId community-id
:users pks}]
:js-response true
:on-success #(re-frame/dispatch [::people-invited %])
:on-error #(do
(log/error "failed to invite-user community" %)
(re-frame/dispatch [::failed-to-share-community %]))}]})))
(re-frame/reg-event-fx :communities/invite-people-pressed
(fn [{:keys [db]} [id]]
{:db (assoc db :communities/community-id-input id)
:fx [[:dispatch [:hide-bottom-sheet]]
[:dispatch [:open-modal :legacy-invite-people-community {:invite? true}]]]}))
(re-frame/reg-event-fx :communities/share-community-pressed
(fn [{:keys [db]} [id]]
{:db (assoc db :communities/community-id-input id)
:fx [[:dispatch [:hide-bottom-sheet]]
[:dispatch [:open-modal :legacy-invite-people-community {}]]]}))
(rf/defn people-invited
{:events [::people-invited]}
[cofx response-js]
@ -90,6 +41,14 @@
[:sanitize-messages-and-process-response response-js]
[:activity-center.notifications/fetch-unread-count]]}))
(rf/defn member-banned
{:events [::member-banned]}
[cofx response-js]
(rf/merge cofx
(bottom-sheet/hide-bottom-sheet-old)
(handle-response response-js)
(activity-center/notifications-fetch-unread-count)))
(rf/defn member-ban
{:events [::member-ban]}
[cofx community-id public-key]

View File

@ -41,21 +41,24 @@
(defn user
[{:keys [short-chat-key primary-name secondary-name photo-path online? contact? verified?
untrustworthy? on-press on-long-press accessory customization-color theme
allow-multiple-presses?]}]
allow-multiple-presses? disabled?]}]
[rn/touchable-highlight
{:style container-style
:underlay-color (colors/resolve-color customization-color theme 5)
:allow-multiple-presses? allow-multiple-presses?
:accessibility-label :user-list
:on-press (when on-press on-press)
:on-long-press (when on-long-press on-long-press)}
:on-long-press (when on-long-press on-long-press)
:disabled disabled?}
[:<>
[user-avatar/user-avatar
{:full-name primary-name
:profile-picture photo-path
:online? online?
:size :small}]
[rn/view {:style {:margin-horizontal 8 :flex 1}}
[rn/view
{:style {:margin-horizontal 8
:flex 1}}
[author/view
{:primary-name primary-name
:secondary-name secondary-name
@ -69,4 +72,4 @@
:style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40)}}
short-chat-key])]
(when accessory
[action-icon accessory customization-color theme])]])
[action-icon accessory customization-color disabled? theme])]])

View File

@ -10,7 +10,10 @@
(def ui-themed
{:no-funds
{:light (js/require "../resources/images/ui2/no-funds-light.png")
:dark (js/require "../resources/images/ui2/no-funds-dark.png")}})
:dark (js/require "../resources/images/ui2/no-funds-dark.png")}
:no-contacts-to-chat
{:light (js/require "../resources/images/ui2/no-contacts-to-chat-light.png")
:dark (js/require "../resources/images/ui2/no-contacts-to-chat-dark.png")}})
(defn get-themed-image
[k theme]

View File

@ -12,5 +12,5 @@
(defn contacts-section-header
[{:keys [title]}]
(let [theme (quo.theme/use-theme-value)]
[quo/divider-label {:container-style {:background-color (style/contacts-section-header theme)}}
[quo/divider-label {:container-style (style/contacts-section-header theme)}
title]))

View File

@ -5,7 +5,7 @@
[utils.re-frame :as rf]))
(defn contact-list-item
[{:keys [on-press on-long-press accessory allow-multiple-presses?]}
[{:keys [on-press on-long-press accessory allow-multiple-presses? disabled?]}
{:keys [primary-name secondary-name public-key compressed-key ens-verified added?]}
theme]
(let [photo-path (rf/sub [:chats/photo-path public-key])
@ -24,4 +24,5 @@
:contact? added?
:on-press on-press
:on-long-press on-long-press
:accessory accessory}]))
:accessory accessory
:disabled? disabled?}]))

View File

@ -101,6 +101,7 @@
{:keys [primary-name public-key]} (when one-contact-selected?
(rf/sub [:contacts/contact-by-identity
(first selected-contacts)]))]
(rn/use-unmount #(rf/dispatch [:group-chat/clear-contacts]))
[rn/view {:flex 1}
[rn/view {:padding-horizontal 20}
[quo/button

View File

@ -0,0 +1,48 @@
(ns status-im.contexts.communities.actions.invite-contacts.style
(:require
[quo.foundations.colors :as colors]
[react-native.safe-area :as safe-area]))
(def contact-selection-heading
{:flex-direction :row
:justify-content :space-between
:align-items :flex-end
:margin-top 24
:margin-bottom 16})
(def chat-button
{:position :absolute
:bottom (safe-area/get-bottom)
:left 20
:right 20})
(defn no-contacts
[]
{:margin-bottom (+ 96 (safe-area/get-bottom))
:flex 1
:justify-content :center
:align-items :center})
(def context-tag
{:align-self :flex-start
:margin-top -8
:margin-bottom 12})
(def no-contacts-text
{:margin-bottom 2
:margin-top 12})
(def no-contacts-button-container
{:margin-top 20
:margin-bottom 12})
(defn section-list-container-style
[theme]
{:padding-bottom 70
:background-color (colors/theme-colors colors/white
colors/neutral-95
theme)})
(defn invite-to-community-text
[theme]
{:color (colors/theme-colors colors/neutral-100 colors/white theme)})

View File

@ -0,0 +1,141 @@
(ns status-im.contexts.communities.actions.invite-contacts.view
(:require
[quo.core :as quo]
[quo.foundations.resources :as resources]
[quo.theme]
[react-native.core :as rn]
[react-native.gesture :as gesture]
[react-native.share :as share]
[status-im.common.contact-list-item.view :as contact-list-item]
[status-im.common.contact-list.view :as contact-list]
[status-im.contexts.communities.actions.invite-contacts.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn- no-contacts-view
[{:keys [theme id]}]
(let [customization-color (rf/sub [:profile/customization-color])
{:keys [universal-profile-url]} (rf/sub [:profile/profile])
on-press-share-community (rn/use-callback
#(rf/dispatch [:communities/share-community-url-with-data
id]))
on-press-share-profile (rn/use-callback #(share/open {:url universal-profile-url})
[universal-profile-url])]
[rn/view
{:style (style/no-contacts)}
[rn/image {:source (resources/get-themed-image :no-contacts-to-chat theme)}]
[quo/text
{:weight :semi-bold
:size :paragraph-1
:style style/no-contacts-text}
(i18n/label :t/you-have-no-contacts)]
[quo/text
{:weight :regular
:size :paragraph-2}
(i18n/label :t/dont-yell-at-me)]
[quo/button
{:customization-color customization-color
:theme theme
:type :primary
:size 32
:container-style style/no-contacts-button-container
:on-press on-press-share-community}
(i18n/label :t/send-community-link)]
[quo/button
{:customization-color customization-color
:theme theme
:type :grey
:size 32
:on-press on-press-share-profile}
(i18n/label :t/invite-friends-to-status)]]))
(defn- contact-item
[{:keys [public-key]
:as item}]
(let [user-selected? (rf/sub [:is-contact-selected? public-key])
{:keys [id]} (rf/sub [:get-screen-params])
community-members-keys (set (keys (rf/sub [:communities/community-members id])))
community-member? (boolean (community-members-keys public-key))
on-toggle (fn []
(when-not community-member?
(if user-selected?
(rf/dispatch [:deselect-contact public-key])
(rf/dispatch [:select-contact public-key]))))]
[contact-list-item/contact-list-item
{:on-press on-toggle
:allow-multiple-presses? true
:accessory {:type :checkbox
:disabled? community-member?
:checked? (or community-member? user-selected?)
:on-check on-toggle}
:disabled? community-member?}
item]))
(defn view-internal
[{:keys [theme]}]
(fn []
(rn/use-unmount #(rf/dispatch [:group-chat/clear-contacts]))
(let [customization-color (rf/sub [:profile/customization-color])
{:keys [id]} (rf/sub [:get-screen-params])
contacts (rf/sub [:contacts/filtered-active-sections])
selected (rf/sub [:group/selected-contacts])
{:keys [name images]} (rf/sub [:communities/community id])
selected-contacts-count (count selected)
on-press (fn []
(rf/dispatch [:communities/share-community-confirmation-pressed
selected id])
(rf/dispatch [:navigate-back])
(rf/dispatch [:toasts/upsert
{:type :positive
:theme theme
:text (if (= 1 selected-contacts-count)
(i18n/label :t/one-user-was-invited)
(i18n/label
:t/n-users-were-invited
{:count selected-contacts-count}))}]))
{window-height :height} (rn/get-window)]
[rn/view {:style {:flex 1}}
[rn/view {:style {:padding-horizontal 20}}
[quo/button
{:type :grey
:size 32
:icon-only? true
:on-press #(rf/dispatch [:navigate-back])}
:i/close]
[rn/view {:style style/contact-selection-heading}
[quo/text
{:weight :semi-bold
:size :heading-1
:style (style/invite-to-community-text theme)}
(i18n/label :t/invite-to-community)]]
[quo/context-tag
{:type :community
:size 24
:community-logo (:thumbnail images)
:community-name name
:container-style style/context-tag}]]
(if (empty? contacts)
[no-contacts-view
{:theme theme
:id id}]
[:<>
[gesture/section-list
{:key-fn :public-key
:sticky-section-headers-enabled true
:sections contacts
:render-section-header-fn contact-list/contacts-section-header
:content-container-style (style/section-list-container-style theme)
:render-fn contact-item
:style {:height window-height}}]
(when (pos? selected-contacts-count)
[quo/button
{:type :primary
:accessibility-label :next-button
:customization-color customization-color
:container-style style/chat-button
:on-press on-press}
(if (= 1 selected-contacts-count)
(i18n/label :t/invite-1-user)
(i18n/label :t/invite-n-users {:count selected-contacts-count}))])])])))
(def view (quo.theme/with-theme view-internal))

View File

@ -1,11 +1,8 @@
(ns status-im.contexts.communities.events
(:require
[clojure.string :as string]
[legacy.status-im.data-store.chats :as data-store.chats]
[legacy.status-im.data-store.communities :as data-store.communities]
[legacy.status-im.mailserver.core :as mailserver]
[react-native.platform :as platform]
[react-native.share :as share]
[schema.core :as schema]
[status-im.constants :as constants]
[status-im.contexts.chat.messenger.messages.link-preview.events :as link-preview.events]
@ -14,9 +11,9 @@
status-im.contexts.communities.actions.airdrop-addresses.events
status-im.contexts.communities.actions.community-options.events
status-im.contexts.communities.actions.leave.events
[status-im.contexts.communities.utils :as utils]
[status-im.navigation.events :as navigation]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn handle-community
@ -152,43 +149,100 @@
:on-success #(rf/dispatch [:communities/fetched-collapsed-categories-success %])
:on-error #(log/error "failed to fetch collapsed community categories" %)}]}))
(rf/reg-event-fx :communities/get-community-channel-share-data
(fn [_ [chat-id on-success]]
(let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id)]
{:json-rpc/call
[{:method "wakuext_shareCommunityChannelURLWithData"
:params [{:CommunityID community-id :ChannelID channel-id}]
:on-success on-success
:on-error (fn [err]
(log/error "failed to retrieve community channel url with data"
{:error err
:chat-id chat-id
:event :communities/get-community-channel-share-data}))}]})))
(defn initialize-permission-addresses
[{:keys [db]} [community-id]]
(when community-id
(let [accounts (utils/sorted-non-watch-only-accounts db)
addresses (set (map :address accounts))]
{:db (update-in db
[:communities community-id]
assoc
:previous-share-all-addresses? true
:share-all-addresses? true
:previous-permission-addresses addresses
:selected-permission-addresses addresses
:airdrop-address (:address (first accounts)))})))
(rf/reg-event-fx :communities/share-community-channel-url-with-data
(fn [_ [chat-id]]
(let [title (i18n/label :t/channel-on-status)
on-success (fn [url]
(share/open
(if platform/ios?
{:activityItemSources [{:placeholderItem {:type "text"
:content title}
:item {:default {:type "url"
:content url}}
:linkMetadata {:title title}}]}
{:title title
:subject title
:message url
:url url
:isNewTask true})))]
{:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]})))
(rf/reg-event-fx :communities/initialize-permission-addresses
initialize-permission-addresses)
(rf/reg-event-fx :communities/share-community-channel-url-qr-code
(fn [_ [chat-id]]
(let [on-success #(rf/dispatch [:open-modal :share-community-channel
{:chat-id chat-id
:url %}])]
{:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]})))
(defn update-previous-permission-addresses
[{:keys [db]} [community-id]]
(when community-id
(let [accounts (utils/sorted-non-watch-only-accounts db)
selected-permission-addresses (get-in db
[:communities community-id
:selected-permission-addresses])
selected-accounts (filter #(contains? selected-permission-addresses (:address %))
accounts)
current-airdrop-address (get-in db [:communities community-id :airdrop-address])
share-all-addresses? (get-in db [:communities community-id :share-all-addresses?])]
{:db (update-in db
[:communities community-id]
assoc
:previous-share-all-addresses? share-all-addresses?
:previous-permission-addresses selected-permission-addresses
:airdrop-address (if (contains? selected-permission-addresses
current-airdrop-address)
current-airdrop-address
(:address (first selected-accounts))))})))
(rf/reg-event-fx :communities/update-previous-permission-addresses
update-previous-permission-addresses)
(defn toggle-selected-permission-address
[{:keys [db]} [address community-id]]
(let [selected-permission-addresses
(get-in db [:communities community-id :selected-permission-addresses])
updated-selected-permission-addresses
(if (contains? selected-permission-addresses address)
(disj selected-permission-addresses address)
(conj selected-permission-addresses address))]
{:db (assoc-in db
[:communities community-id :selected-permission-addresses]
updated-selected-permission-addresses)
:fx [(when community-id
[:dispatch
[:communities/check-permissions-to-join-community community-id
updated-selected-permission-addresses :based-on-client-selection]])]}))
(rf/reg-event-fx :communities/toggle-selected-permission-address
toggle-selected-permission-address)
(defn toggle-share-all-addresses
[{:keys [db]} [community-id]]
(let [share-all-addresses? (get-in db [:communities community-id :share-all-addresses?])
next-share-all-addresses? (not share-all-addresses?)
accounts (utils/sorted-non-watch-only-accounts db)
addresses (set (map :address accounts))]
{:db (update-in db
[:communities community-id]
assoc
:share-all-addresses? next-share-all-addresses?
:selected-permission-addresses addresses)
:fx [(when (and community-id next-share-all-addresses?)
[:dispatch
[:communities/check-permissions-to-join-community community-id
addresses :based-on-client-selection]])]}))
(rf/reg-event-fx :communities/toggle-share-all-addresses
toggle-share-all-addresses)
(rf/reg-event-fx :communities/reset-selected-permission-addresses
(fn [{:keys [db]} [community-id]]
(when community-id
{:db (update-in db
[:communities community-id]
assoc
:selected-permission-addresses
(get-in db [:communities community-id :previous-permission-addresses])
:share-all-addresses?
(get-in db [:communities community-id :previous-share-all-addresses?]))
:fx [[:dispatch [:communities/check-permissions-to-join-community community-id]]]})))
(rf/reg-event-fx :communities/set-airdrop-address
(fn [{:keys [db]} [address community-id]]
{:db (assoc-in db [:communities community-id :airdrop-address] address)}))
(defn community-fetched
[{:keys [db]} [community-id community]]

View File

@ -0,0 +1,100 @@
(ns status-im.contexts.communities.sharing.events
(:require [legacy.status-im.data-store.chats :as data-store.chats]
[react-native.platform :as platform]
[react-native.share :as share]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(rf/reg-event-fx :communities/invite-people-pressed
(fn [{:keys [db]} [id]]
{:db (assoc db :communities/community-id-input id)
:fx [[:dispatch [:hide-bottom-sheet]]
[:dispatch [:open-modal :invite-people-community {:id id}]]]}))
(rf/reg-event-fx :communities/share-community-pressed
(fn [{:keys [db]} [id]]
{:db (assoc db :communities/community-id-input id)
:fx [[:dispatch [:hide-bottom-sheet]]
[:dispatch [:open-modal :legacy-invite-people-community {:id id}]]]}))
(rf/reg-event-fx :communities/share-community-confirmation-pressed
(fn [_ [users-public-keys community-id]]
{:fx [[:json-rpc/call
[{:method "wakuext_shareCommunity"
:params [{:communityId community-id
:users users-public-keys}]
:js-response true
:on-success [:sanitize-messages-and-process-response]
:on-error (fn [err]
(log/error {:message "failed to share community"
:community-id community-id
:err err}))}]]]}))
(rf/reg-event-fx :communities/share-community-channel-url-qr-code
(fn [_ [chat-id]]
(let [on-success #(rf/dispatch [:open-modal :share-community-channel
{:chat-id chat-id
:url %}])]
{:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]})))
(rf/reg-event-fx :communities/share-community-url-with-data
(fn [_ [community-id]]
(let [title (i18n/label :t/community-on-status)
on-success (fn [url]
(share/open
(if platform/ios?
{:activityItemSources [{:placeholderItem {:type "text"
:content title}
:item {:default {:type "url"
:content url}}
:linkMetadata {:title title}}]}
{:title title
:subject title
:message url
:url url
:isNewTask true})))]
{:fx [[:dispatch [:communities/get-community-share-data community-id on-success]]]})))
(rf/reg-event-fx :communities/get-community-channel-share-data
(fn [_ [chat-id on-success]]
(let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id)]
{:json-rpc/call
[{:method "wakuext_shareCommunityChannelURLWithData"
:params [{:CommunityID community-id :ChannelID channel-id}]
:on-success on-success
:on-error (fn [err]
(log/error "failed to retrieve community channel url with data"
{:error err
:chat-id chat-id
:event :communities/get-community-channel-share-data}))}]})))
(rf/reg-event-fx :communities/get-community-share-data
(fn [_ [community-id on-success]]
{:json-rpc/call
[{:method "wakuext_shareCommunityURLWithData"
:params [community-id]
:on-success on-success
:on-error (fn [err]
(log/error "failed to retrieve community url with data"
{:error err
:community-id community-id
:event :communities/get-community-share-data}))}]}))
(rf/reg-event-fx :communities/share-community-channel-url-with-data
(fn [_ [chat-id]]
(let [title (i18n/label :t/channel-on-status)
on-success (fn [url]
(share/open
(if platform/ios?
{:activityItemSources [{:placeholderItem {:type "text"
:content title}
:item {:default {:type "url"
:content url}}
:linkMetadata {:title title}}]}
{:title title
:subject title
:message url
:url url
:isNewTask true})))]
{:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]})))

View File

@ -22,6 +22,7 @@
status-im.contexts.chat.messenger.photo-selector.events
status-im.contexts.communities.events
status-im.contexts.communities.overview.events
status-im.contexts.communities.sharing.events
status-im.contexts.onboarding.common.overlay.events
status-im.contexts.onboarding.events
status-im.contexts.profile.events

View File

@ -14,10 +14,12 @@
[status-im.contexts.chat.messenger.messages.view :as chat]
[status-im.contexts.chat.messenger.photo-selector.view :as photo-selector]
[status-im.contexts.communities.actions.accounts-selection.view :as communities.accounts-selection]
[status-im.contexts.communities.actions.addresses-for-permissions.view :as addresses-for-permissions]
[status-im.contexts.communities.actions.addresses-for-permissions.view :as
addresses-for-permissions]
[status-im.contexts.communities.actions.airdrop-addresses.view :as airdrop-addresses]
[status-im.contexts.communities.actions.channel-view-details.view :as
channel-view-channel-members-and-details]
[status-im.contexts.communities.actions.invite-contacts.view :as communities.invite]
[status-im.contexts.communities.actions.request-to-join.view :as join-menu]
[status-im.contexts.communities.actions.share-community-channel.view :as share-community-channel]
[status-im.contexts.communities.discover.view :as communities.discover]
@ -461,6 +463,10 @@
{:modalPresentationStyle :overCurrentContext})
:component scan-profile-qr-page/view}
{:name :invite-people-community
:options {:sheet? true}
:component communities.invite/view}
;; Settings
{:name :settings-password

View File

@ -92,6 +92,12 @@
(fn [profile]
(:test-networks-enabled? profile)))
(re-frame/reg-sub
:profile/universal-profile-url
:<- [:profile/profile]
(fn [profile]
(:universal-profile-url profile)))
(re-frame/reg-sub
:profile/is-goerli-enabled?
:<- [:profile/profile]

View File

@ -500,9 +500,8 @@ class CommunityView(HomeView):
community_element.long_press_until_element_is_shown(self.share_community_button)
self.share_community_button.click()
for user_name in user_names_to_share:
user_contact = self.element_by_text_part(user_name)
user_contact.scroll_and_click()
self.share_community_link_button.click()
Button(self.driver, xpath="//*[@content-desc='author-primary-name'][@text='%s']" % user_name).click()
self.setup_chat_button.click()
class PreviewMessage(ChatElementByText):

View File

@ -154,6 +154,7 @@
"changed-amount-warning": "Amount was changed from {{old}} to {{new}}",
"changed-asset-warning": "Asset was changed from {{old}} to {{new}}",
"channel-on-status": "Channel on Status",
"community-on-status": "Community on Status",
"chaos-mode": "Chaos mode",
"chaos-unicorn-day": "Chaos Unicorn Day",
"chaos-unicorn-day-details": "🦄🦄🦄🦄🦄🦄🦄🚀!",
@ -2574,5 +2575,12 @@
"display": "Display",
"testnet-mode-enabled": "Testnet mode enabled",
"online-community-member": "Online",
"offline-community-member": "Offline"
"offline-community-member": "Offline",
"invite-to-community": "Invite to community",
"invite-n-users": "Invite {{count}} users",
"invite-1-user": "Invite 1 user",
"one-user-was-invited": "1 user was invited",
"n-users-were-invited": "{{count}} users were invited",
"invite-friend-to-status": "Invite friends to Status",
"send-community-link": "Send community link"
}