Skip to content

Commit 9879f97

Browse files
committed
updates
1 parent 3635108 commit 9879f97

File tree

8 files changed

+102
-107
lines changed

8 files changed

+102
-107
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
[chat-id]
9898
{:icon :i/qr-code
9999
:accessibility-label :chat-show-qr-code
100-
:on-press #(rf/dispatch [:communities/community-channel-url-qr-code-with-data chat-id])
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

src/status_im/contexts/communities/actions/share_community_channel/style.cljs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
(def scan-notice
99
{:color colors/neutral-40
10-
:margin-top 12
10+
:margin-top 16
1111
:margin-left :auto
1212
:margin-right :auto})
1313

1414
(def qr-size 500)
1515

1616
(def qr-code-wrapper
1717
{:padding-horizontal 20
18+
:margin-top 8
1819
:align-items :center})
1920

2021
(def gradient-cover-padding 20)

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

+35-44
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,43 @@
66
[status-im.common.qr-codes.view :as qr-codes]
77
[status-im.contexts.communities.actions.share-community-channel.style :as style]
88
[utils.i18n :as i18n]
9-
[utils.image-server :as image-server]
109
[utils.re-frame :as rf]))
1110

1211
(defn view
1312
[]
14-
(let [padding-top (:top (safe-area/get-insets))]
15-
(fn []
16-
(let [chat (rf/sub [:chats/current-chat-chat-view])
17-
{:keys [color emoji chat-name]} chat
18-
mediaserver-port (rf/sub [:mediaserver/port])
19-
window-width (rf/sub [:dimensions/window-width])
20-
{:keys [url]} (rf/sub [:get-screen-params])
21-
qr-media-server-uri (image-server/get-qr-image-uri-for-any-url
22-
{:url url
23-
:port mediaserver-port
24-
:qr-size style/qr-size
25-
:error-level :highest})
26-
title (i18n/label :t/share-channel)]
27-
[quo/overlay {:type :shell}
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+
(prn color emoji chat-name chat-id)
18+
[quo/overlay {:type :shell}
19+
[rn/view
20+
{:style {:padding-top (safe-area/get-top)}
21+
:key :share-community}
22+
[quo/page-nav
23+
{:icon-name :i/close
24+
:on-press #(rf/dispatch [:navigate-back])
25+
:background :blur
26+
:accessibility-label :top-bar}]
27+
[quo/text-combinations
28+
{:container-style style/header-container
29+
:title (i18n/label :t/share-channel)}]
30+
[rn/view {:style style/qr-code-wrapper}
31+
[quo/gradient-cover
32+
{:container-style
33+
(style/gradient-cover-wrapper window-width)
34+
:customization-color color}]
2835
[rn/view
29-
{:style {:padding-top padding-top}
30-
:key :share-community}
31-
[quo/page-nav
32-
{:icon-name :i/close
33-
:on-press #(rf/dispatch [:navigate-back])
34-
:background :blur
35-
:accessibility-label :top-bar}]
36-
[quo/text-combinations
37-
{:container-style style/header-container
38-
:title title}]
39-
[rn/view {:style style/qr-code-wrapper}
40-
[quo/gradient-cover
41-
{:container-style
42-
(style/gradient-cover-wrapper window-width)
43-
:customization-color color}]
44-
[rn/view
45-
{:style {:padding-vertical 12}}
46-
[qr-codes/qr-code
47-
{:size (style/qr-code-size window-width)
48-
:qr-image-uri qr-media-server-uri
49-
:avatar :channel
50-
:customization-color color
51-
:emoji emoji
52-
:full-name chat-name}]]]
53-
[quo/text
54-
{:size :paragraph-2
55-
:weight :regular
56-
:style style/scan-notice}
57-
(i18n/label :t/scan-with-status-app)]]]))))
36+
{:style {:padding-vertical 12}}
37+
[qr-codes/qr-code
38+
{:size (style/qr-code-size window-width)
39+
:url url
40+
:avatar :channel
41+
:customization-color color
42+
:emoji emoji
43+
:full-name chat-name}]]]
44+
[quo/text
45+
{:size :paragraph-2
46+
:weight :regular
47+
:style style/scan-notice}
48+
(i18n/label :t/scan-with-status-app)]]])))

src/status_im/contexts/communities/events.cljs

+32-58
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
status-im.contexts.communities.actions.addresses-for-permissions.events
1313
status-im.contexts.communities.actions.community-options.events
1414
status-im.contexts.communities.actions.leave.events
15-
[status-im.contexts.communities.utils :as utils]
1615
[status-im.navigation.events :as navigation]
1716
[taoensso.timbre :as log]
1817
[utils.i18n :as i18n]
@@ -164,35 +163,33 @@
164163
(defn initialize-permission-addresses
165164
[{:keys [db]} [community-id]]
166165
(when community-id
167-
(let [accounts (utils/sorted-non-watch-only-accounts db)
168-
addresses (set (map :address accounts))]
166+
(let [accounts (get-in db [:wallet :accounts])
167+
sorted-accounts (sort-by :position (vals accounts))
168+
addresses (set (map :address sorted-accounts))]
169169
{:db (update-in db
170170
[:communities community-id]
171171
assoc
172-
:previous-share-all-addresses? true
173-
:share-all-addresses? true
174172
:previous-permission-addresses addresses
175173
:selected-permission-addresses addresses
176-
:airdrop-address (:address (first accounts)))})))
174+
:airdrop-address (:address (first sorted-accounts)))})))
177175

178176
(rf/reg-event-fx :communities/initialize-permission-addresses
179177
initialize-permission-addresses)
180178

181179
(defn update-previous-permission-addresses
182180
[{:keys [db]} [community-id]]
183181
(when community-id
184-
(let [accounts (utils/sorted-non-watch-only-accounts db)
182+
(let [accounts (get-in db [:wallet :accounts])
183+
sorted-accounts (sort-by :position (vals accounts))
185184
selected-permission-addresses (get-in db
186185
[:communities community-id
187186
:selected-permission-addresses])
188187
selected-accounts (filter #(contains? selected-permission-addresses (:address %))
189-
accounts)
190-
current-airdrop-address (get-in db [:communities community-id :airdrop-address])
191-
share-all-addresses? (get-in db [:communities community-id :share-all-addresses?])]
188+
sorted-accounts)
189+
current-airdrop-address (get-in db [:communities community-id :airdrop-address])]
192190
{:db (update-in db
193191
[:communities community-id]
194192
assoc
195-
:previous-share-all-addresses? share-all-addresses?
196193
:previous-permission-addresses selected-permission-addresses
197194
:airdrop-address (if (contains? selected-permission-addresses
198195
current-airdrop-address)
@@ -221,42 +218,31 @@
221218
(rf/reg-event-fx :communities/toggle-selected-permission-address
222219
toggle-selected-permission-address)
223220

224-
(defn toggle-share-all-addresses
225-
[{:keys [db]} [community-id]]
226-
(let [share-all-addresses? (get-in db [:communities community-id :share-all-addresses?])
227-
accounts (utils/sorted-non-watch-only-accounts db)
228-
addresses (set (map :address accounts))]
229-
{:db (update-in db
230-
[:communities community-id]
231-
(fn [community]
232-
(-> community
233-
(assoc :share-all-addresses? (not share-all-addresses?))
234-
(cond-> (not share-all-addresses?)
235-
(assoc :selected-permission-addresses addresses)))))}))
236-
237-
(rf/reg-event-fx :communities/toggle-share-all-addresses
238-
toggle-share-all-addresses)
239-
240221
(rf/reg-event-fx :communities/reset-selected-permission-addresses
241222
(fn [{:keys [db]} [community-id]]
242223
(when community-id
243-
{:db (update-in db
244-
[:communities community-id]
245-
assoc
246-
:selected-permission-addresses
247-
(get-in db [:communities community-id :previous-permission-addresses])
248-
:share-all-addresses?
249-
(get-in db [:communities community-id :previous-share-all-addresses?]))
224+
{:db (assoc-in db
225+
[:communities community-id :selected-permission-addresses]
226+
(get-in db [:communities community-id :previous-permission-addresses]))
250227
:fx [[:dispatch [:communities/check-permissions-to-join-community community-id]]]})))
251228

252-
(rf/reg-event-fx :communities/share-community-channel-url-with-data
253-
(fn [_ [chat-id]]
254-
(let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id)
255-
title (i18n/label :t/channel-on-status)]
229+
(rf/reg-event-fx :communities/get-community-channel-share-data
230+
(fn [_ [chat-id on-success]]
231+
(let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id)]
256232
{:json-rpc/call
257233
[{:method "wakuext_shareCommunityChannelURLWithData"
258234
:params [{:CommunityID community-id :ChannelID channel-id}]
259-
:on-success (fn [url]
235+
:on-success on-success
236+
:on-error (fn [err]
237+
(log/error "failed to retrieve community channel url with data"
238+
{:error err
239+
:chat-id chat-id
240+
:event :communities/get-community-channel-share-data}))}]})))
241+
242+
(rf/reg-event-fx :communities/share-community-channel-url-with-data
243+
(fn [_ [chat-id]]
244+
(let [title (i18n/label :t/channel-on-status)
245+
on-success (fn [url]
260246
(share/open
261247
(if platform/ios?
262248
{:activityItemSources [{:placeholderItem {:type "text"
@@ -268,27 +254,15 @@
268254
:subject title
269255
:message url
270256
:url url
271-
:isNewTask true})))
272-
:on-error (fn [err]
273-
(log/error "failed to retrieve community channel url with data"
274-
{:error err
275-
:chat-id chat-id
276-
:event "share-community-channel-url-with-data"}))}]})))
257+
:isNewTask true})))]
258+
{:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]})))
277259

278-
(rf/reg-event-fx :communities/community-channel-url-qr-code-with-data
260+
(rf/reg-event-fx :communities/share-community-channel-url-qr-code
279261
(fn [_ [chat-id]]
280-
(let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id)]
281-
{:json-rpc/call
282-
[{:method "wakuext_shareCommunityChannelURLWithData"
283-
:params [{:CommunityID community-id
284-
:ChannelID channel-id}]
285-
:on-success (fn [url]
286-
(rf/dispatch [:open-modal :share-community-channel {:url url}]))
287-
:on-error (fn [err]
288-
(log/error "failed to retrieve community channel url with data"
289-
{:error err
290-
:chat-id chat-id
291-
:event [:communities/community-channel-url-qr-code-with-data]}))}]})))
262+
(let [on-success #(rf/dispatch [:open-modal :share-community-channel
263+
{:chat-id chat-id
264+
:url %}])]
265+
{:fx [[:dispatch [:communities/get-community-channel-share-data chat-id on-success]]]})))
292266

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

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)))))))

0 commit comments

Comments
 (0)