Skip to content

Commit 71072dd

Browse files
committed
feat: support /cc/encoded-data and /cc/community-channel-id
1 parent e67a744 commit 71072dd

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

src/status_im/router/core.cljs

+27-13
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343

4444
(def routes
4545
[""
46-
{handled-schemes {["c/" :community-data] :community
47-
["cc/" :community-channel-id] :community-chat
48-
["p/" :chat-id] :private-chat
49-
["cr/" :community-id] :community-requests
50-
"g/" group-chat-extractor
51-
["wallet/" :account] :wallet-account
52-
["u/" :user-data] :user
53-
"c" :community
54-
"u" :user}
46+
{handled-schemes {["c/" :community-data] :community
47+
["cc/" :community-data] :community-chat
48+
["p/" :chat-id] :private-chat
49+
["cr/" :community-id] :community-requests
50+
"g/" group-chat-extractor
51+
["wallet/" :account] :wallet-account
52+
["u/" :user-data] :user
53+
"c" :community
54+
"u" :user}
5555
ethereum-scheme eip-extractor}])
5656

5757
(defn parse-query-params
@@ -68,7 +68,7 @@
6868

6969
(defn match-uri
7070
[uri]
71-
(let [ ;; bidi has trouble parse path with `=` in it extract `=` here and add back to parsed
71+
(let [;; bidi has trouble parse path with `=` in it extract `=` here and add back to parsed
7272
;; base64url regex based on https://datatracker.ietf.org/doc/html/rfc4648#section-5 may
7373
;; include invalid base64 (invalid length, length of any base64 encoded string must be a
7474
;; multiple of 4)
@@ -80,7 +80,7 @@
8080
(if equal-end-of-base64url (string/replace-first uri equal-end-of-base64url "") uri)
8181

8282
fragment (parse-fragment uri)
83-
ens? (ens/is-valid-eth-name? fragment)
83+
ens? (ens/is-valid-eth-name? fragment)
8484

8585
{:keys [handler route-params] :as parsed}
8686
(assoc (bidi/match-route routes uri-without-equal-in-path)
@@ -96,9 +96,19 @@
9696
(and equal-end-of-base64url (= handler :community) (:community-data route-params))
9797
(update-in [:route-params :community-data] #(str % equal-end-of-base64url))
9898

99-
(and fragment (= handler :community-chat) (:community-channel-id route-params))
99+
(and equal-end-of-base64url (= handler :community-chat) (:community-data route-params))
100+
(update-in [:route-params :community-data] #(str % equal-end-of-base64url))
101+
102+
(and fragment (= handler :community-chat) (:community-data route-params))
100103
(assoc-in [:route-params :community-id] fragment)
101104

105+
(and fragment
106+
(= handler :community-chat)
107+
(:community-data route-params)
108+
(string? (:community-data route-params))
109+
(string/includes? (:community-data route-params) "-"))
110+
(assoc-in [:route-params :community-channel-id] (:community-data route-params))
111+
102112
(and equal-end-of-base64url (= handler :user) (:user-data route-params))
103113
(update-in [:route-params :user-data] #(str % equal-end-of-base64url))
104114

@@ -290,9 +300,13 @@
290300
(cb {:type (community-route-type route-params)
291301
:community-id (:community-id route-params)})
292302

293-
(= handler :community-chat)
303+
(and (= handler :community-chat) (:community-channel-id route-params) (:community-id route-params))
294304
(match-community-channel-async route-params cb)
295305

306+
(and (= handler :community-chat) (:community-id route-params))
307+
(cb {:type (community-route-type route-params)
308+
:community-id (:community-id route-params)})
309+
296310
;; NOTE: removed in `match-uri`, might need this in the future
297311
(= handler :wallet-account)
298312
(cb (match-wallet-account route-params))

src/status_im/router/core_test.cljs

+18-2
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,32 @@
4040

4141
"https://status.app/cc/G54AAKwObLdpiGjXnckYzRcOSq0QQAS_CURGfqVU42ceGHCObstUIknTTZDOKF3E8y2MSicncpO7fTskXnoACiPKeejvjtLTGWNxUhlT7fyQS7Jrr33UVHluxv_PLjV2ePGw5GQ33innzeK34pInIgUGs5RjdQifMVmURalxxQKwiuoY5zwIjixWWRHqjHM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
4242
[:community-chat
43-
{:chat-data
43+
{:community-data
4444
"G54AAKwObLdpiGjXnckYzRcOSq0QQAS_CURGfqVU42ceGHCObstUIknTTZDOKF3E8y2MSicncpO7fTskXnoACiPKeejvjtLTGWNxUhlT7fyQS7Jrr33UVHluxv_PLjV2ePGw5GQ33innzeK34pInIgUGs5RjdQifMVmURalxxQKwiuoY5zwIjixWWRHqjHM="
4545
:community-id "zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"}]
4646

4747
"status-app://cc/G54AAKwObLdpiGjXnckYzRcOSq0QQAS_CURGfqVU42ceGHCObstUIknTTZDOKF3E8y2MSicncpO7fTskXnoACiPKeejvjtLTGWNxUhlT7fyQS7Jrr33UVHluxv_PLjV2ePGw5GQ33innzeK34pInIgUGs5RjdQifMVmURalxxQKwiuoY5zwIjixWWRHqjHM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
4848
[:community-chat
49-
{:chat-data
49+
{:community-data
5050
"G54AAKwObLdpiGjXnckYzRcOSq0QQAS_CURGfqVU42ceGHCObstUIknTTZDOKF3E8y2MSicncpO7fTskXnoACiPKeejvjtLTGWNxUhlT7fyQS7Jrr33UVHluxv_PLjV2ePGw5GQ33innzeK34pInIgUGs5RjdQifMVmURalxxQKwiuoY5zwIjixWWRHqjHM="
5151
:community-id "zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"}]
5252

53+
"https://status.app/cc/c432709e-fc73-440d-bb67-cb3a0929dfda#zQ3shZL6dXiFCbDyxnXxwQa9v8QFC2q19subFtyxd7kVszMVo"
54+
[:community-chat
55+
{:community-data
56+
"c432709e-fc73-440d-bb67-cb3a0929dfda"
57+
:community-channel-id
58+
"c432709e-fc73-440d-bb67-cb3a0929dfda"
59+
:community-id "zQ3shZL6dXiFCbDyxnXxwQa9v8QFC2q19subFtyxd7kVszMVo"}]
60+
61+
"status-app://cc/c432709e-fc73-440d-bb67-cb3a0929dfda#zQ3shZL6dXiFCbDyxnXxwQa9v8QFC2q19subFtyxd7kVszMVo"
62+
[:community-chat
63+
{:community-data
64+
"c432709e-fc73-440d-bb67-cb3a0929dfda"
65+
:community-channel-id
66+
"c432709e-fc73-440d-bb67-cb3a0929dfda"
67+
:community-id "zQ3shZL6dXiFCbDyxnXxwQa9v8QFC2q19subFtyxd7kVszMVo"}]
68+
5369
"https://status.app/c/iyKACkQKB0Rvb2RsZXMSJ0NvbG9yaW5nIHRoZSB3b3JsZCB3aXRoIGpveSDigKIg4bSXIOKAohiYohsiByMxMzFEMkYqAwEhMwM=#zQ3shYSHp7GoiXaauJMnDcjwU2yNjdzpXLosAWapPS4CFxc11"
5470
[:community
5571
{:community-data

0 commit comments

Comments
 (0)