Skip to content

Commit 321ff92

Browse files
authored
feat(communities): add feature to share community channel qr code (#18807)
1 parent 28f43ac commit 321ff92

File tree

10 files changed

+148
-19
lines changed

10 files changed

+148
-19
lines changed

src/quo/components/avatars/channel_avatar/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(defn- initials
1313
[{:keys [full-name size customization-color theme]}]
1414
(let [amount-initials (if (#{:size-32 :size-64} size) 2 1)
15-
channel-name (string/replace full-name "#" "")]
15+
channel-name (utils.string/safe-replace full-name "#" "")]
1616
[text/text
1717
(cond-> {:accessibility-label :initials
1818
:style {:color (colors/resolve-color customization-color theme)}

src/status_im/common/qr_codes/view.cljs

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@
3333
(let [qr-media-server-uri (image-server/get-qr-image-uri-for-any-url
3434
{:url url
3535
:port (rf/sub [:mediaserver/port])
36-
:qr-size (or 400 (int size))
36+
:qr-size (or (int size) 400)
3737
:error-level :highest})]
38-
[quo/qr-code (assoc props :qr-image-uri qr-media-server-uri)]))
38+
[quo/qr-code
39+
(assoc props
40+
:qr-image-uri
41+
qr-media-server-uri)]))
3942

4043
(defn get-network-short-name-url
4144
[network]

src/status_im/contexts/communities/actions/chat/view.cljs

+5-5
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@
9494
:label (i18n/label :t/invite-people-from-contacts)})
9595

9696
(defn- action-qr-code
97-
[]
97+
[chat-id]
9898
{:icon :i/qr-code
9999
:accessibility-label :chat-show-qr-code
100-
:on-press not-implemented/alert
100+
:on-press #(rf/dispatch [:communities/share-community-channel-url-qr-code chat-id])
101101
:label (i18n/label :t/show-qr)})
102102

103103
(defn- action-share
@@ -115,7 +115,7 @@
115115
[quo/action-drawer
116116
[[(action-invite-people)
117117
(action-token-requirements)
118-
(action-qr-code)
118+
(action-qr-code chat-id)
119119
(action-share chat-id)]]]
120120

121121
(and (not inside-chat?) (not locked?))
@@ -126,7 +126,7 @@
126126
(action-notification-settings)
127127
(action-pinned-messages)
128128
(action-invite-people)
129-
(action-qr-code)
129+
(action-qr-code chat-id)
130130
(action-share chat-id)]]]
131131

132132
(and inside-chat? (not locked?))
@@ -139,7 +139,7 @@
139139
(when config/fetch-messages-enabled?
140140
(chat-actions/fetch-messages chat-id))
141141
(action-invite-people)
142-
(action-qr-code)
142+
(action-qr-code chat-id)
143143
(action-share chat-id)]]]
144144

145145
:else nil)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(ns status-im.contexts.communities.actions.share-community-channel.style
2+
(:require [quo.foundations.colors :as colors]))
3+
4+
(def header-container
5+
{:padding-horizontal 20
6+
:padding-vertical 12})
7+
8+
(def scan-notice
9+
{:color colors/white-70-blur
10+
:margin-top 16
11+
:margin-left :auto
12+
:margin-right :auto})
13+
14+
(def qr-code-wrapper
15+
{:padding-horizontal 20
16+
:margin-top 8
17+
:align-items :center})
18+
19+
(def gradient-cover-padding 20)
20+
(def qr-code-padding 12)
21+
22+
(defn qr-code-size
23+
[total-width]
24+
(- total-width (* gradient-cover-padding 2) (* qr-code-padding 2)))
25+
26+
(defn gradient-cover-size
27+
[total-width]
28+
(- total-width (* gradient-cover-padding 2)))
29+
30+
(defn gradient-cover-wrapper
31+
[width]
32+
{:width (gradient-cover-size width)
33+
:position :absolute
34+
:border-radius 12
35+
:z-index -1})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(ns status-im.contexts.communities.actions.share-community-channel.view
2+
(:require
3+
[quo.core :as quo]
4+
[react-native.core :as rn]
5+
[react-native.safe-area :as safe-area]
6+
[status-im.common.qr-codes.view :as qr-codes]
7+
[status-im.contexts.communities.actions.share-community-channel.style :as style]
8+
[utils.i18n :as i18n]
9+
[utils.re-frame :as rf]))
10+
11+
(defn view
12+
[]
13+
(fn []
14+
(let [{:keys [url chat-id]} (rf/sub [:get-screen-params])
15+
{:keys [color emoji chat-name]} (rf/sub [:chats/community-channel-ui-details-by-id chat-id])
16+
window-width (rf/sub [:dimensions/window-width])]
17+
[quo/overlay {:type :shell}
18+
[rn/view
19+
{:style {:padding-top (safe-area/get-top)}
20+
:key :share-community}
21+
[quo/page-nav
22+
{:icon-name :i/close
23+
:on-press #(rf/dispatch [:navigate-back])
24+
:background :blur
25+
:accessibility-label :top-bar}]
26+
[quo/text-combinations
27+
{:container-style style/header-container
28+
:title (i18n/label :t/share-channel)}]
29+
[rn/view {:style style/qr-code-wrapper}
30+
[quo/gradient-cover
31+
{:container-style
32+
(style/gradient-cover-wrapper window-width)
33+
:customization-color color}]
34+
[rn/view
35+
{:style {:padding-vertical 12}}
36+
[qr-codes/qr-code
37+
{:size (style/qr-code-size window-width)
38+
:url url
39+
:avatar :channel
40+
:customization-color color
41+
:emoji emoji
42+
:full-name chat-name}]]]
43+
[quo/text
44+
{:size :paragraph-2
45+
:weight :regular
46+
:style style/scan-notice}
47+
(i18n/label :t/scan-with-status-app)]]])))

src/status_im/contexts/communities/events.cljs

+23-11
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,23 @@
252252
(get-in db [:communities community-id :previous-share-all-addresses?]))
253253
:fx [[:dispatch [:communities/check-permissions-to-join-community community-id]]]})))
254254

255-
(rf/reg-event-fx :communities/share-community-channel-url-with-data
256-
(fn [_ [chat-id]]
257-
(let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id)
258-
title (i18n/label :t/channel-on-status)]
255+
(rf/reg-event-fx :communities/get-community-channel-share-data
256+
(fn [_ [chat-id on-success]]
257+
(let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id)]
259258
{:json-rpc/call
260259
[{:method "wakuext_shareCommunityChannelURLWithData"
261260
:params [{:CommunityID community-id :ChannelID channel-id}]
262-
:on-success (fn [url]
261+
:on-success on-success
262+
:on-error (fn [err]
263+
(log/error "failed to retrieve community channel url with data"
264+
{:error err
265+
:chat-id chat-id
266+
:event :communities/get-community-channel-share-data}))}]})))
267+
268+
(rf/reg-event-fx :communities/share-community-channel-url-with-data
269+
(fn [_ [chat-id]]
270+
(let [title (i18n/label :t/channel-on-status)
271+
on-success (fn [url]
263272
(share/open
264273
(if platform/ios?
265274
{:activityItemSources [{:placeholderItem {:type "text"
@@ -271,12 +280,15 @@
271280
:subject title
272281
:message url
273282
:url url
274-
:isNewTask true})))
275-
:on-error (fn [err]
276-
(log/error "failed to retrieve community channel url with data"
277-
{:error err
278-
:chat-id chat-id
279-
:event "share-community-channel-url-with-data"}))}]})))
283+
:isNewTask true})))]
284+
{:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]})))
285+
286+
(rf/reg-event-fx :communities/share-community-channel-url-qr-code
287+
(fn [_ [chat-id]]
288+
(let [on-success #(rf/dispatch [:open-modal :share-community-channel
289+
{:chat-id chat-id
290+
:url %}])]
291+
{:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]})))
280292

281293
(rf/reg-event-fx :communities/set-airdrop-address
282294
(fn [{:keys [db]} [address community-id]]

src/status_im/navigation/screens.cljs

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
addresses-for-permissions]
1717
[status-im.contexts.communities.actions.airdrop-addresses.view :as airdrop-addresses]
1818
[status-im.contexts.communities.actions.request-to-join.view :as join-menu]
19+
[status-im.contexts.communities.actions.share-community-channel.view :as share-community-channel]
1920
[status-im.contexts.communities.discover.view :as communities.discover]
2021
[status-im.contexts.communities.overview.view :as communities.overview]
2122
[status-im.contexts.onboarding.create-password.view :as create-password]
@@ -115,6 +116,10 @@
115116
:options {:sheet? true}
116117
:component join-menu/view}
117118

119+
{:name :share-community-channel
120+
:options options/transparent-screen-options
121+
:component share-community-channel/view}
122+
118123
{:name :community-account-selection
119124
:options {:sheet? true}
120125
:component communities.accounts-selection/view}

src/status_im/subs/chats.cljs

+10
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@
221221
:community-id
222222
:emoji])))
223223

224+
(re-frame/reg-sub
225+
:chats/community-channel-ui-details-by-id
226+
:<- [:chats/chats]
227+
(fn [chats [_ chat-id]]
228+
(select-keys
229+
(get chats chat-id)
230+
[:chat-name
231+
:color
232+
:emoji])))
233+
224234
(re-frame/reg-sub
225235
:chats/current-chat-message-list-view-context
226236
:<- [:chats/current-chat-chat-view]

src/status_im/subs/chats_test.cljs

+16
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,19 @@
161161
(is (not (:can-delete-message-for-everyone? (rf/sub [sub-name]))))
162162
(is (not (:group-admin? (rf/sub [sub-name]))))
163163
(is (not (:message-pin-enabled (rf/sub [sub-name])))))))
164+
165+
(h/deftest-sub :chats/community-channel-ui-details-by-id
166+
[sub-name]
167+
(testing "returns specific ui details of a given community channel chat id"
168+
(let [chats {chat-id (assoc community-chat
169+
:color :army
170+
:emoji "🍑"
171+
:chat-name "test")}]
172+
(swap! rf-db/app-db assoc
173+
:chats
174+
chats)
175+
(let [result (rf/sub [sub-name chat-id])]
176+
(is (= 3 (count (keys result))))
177+
(is (= :army (:color result)))
178+
(is (= "test" (:chat-name result)))
179+
(is (= "🍑" (:emoji result)))))))

translations/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@
12601260
"scan-or-enter-sync-code": "Scan or enter sync code",
12611261
"scan-qr": "Scan QR",
12621262
"scan-qr-code": "Scan QR code",
1263+
"scan-with-status-app": "Scan with the Status app on another device",
12631264
"invalid-qr": "Oops! This QR doesn’t work with Status",
12641265
"search": "Search",
12651266
"search-discover-communities": "Search communities or categories",

0 commit comments

Comments
 (0)