Skip to content

Commit 7b25d28

Browse files
committed
feat: support /cc/encoded-data and /cc/community-channel-id
1 parent c616649 commit 7b25d28

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

src/status_im/router/core.cljs

+28-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)
@@ -79,8 +79,9 @@
7979
uri-without-equal-in-path
8080
(if equal-end-of-base64url (string/replace-first uri equal-end-of-base64url "") uri)
8181

82+
;; fragment is the one after `#`, usually user-id, ens-name, community-id
8283
fragment (parse-fragment uri)
83-
ens? (ens/is-valid-eth-name? fragment)
84+
ens? (ens/is-valid-eth-name? fragment)
8485

8586
{:keys [handler route-params] :as parsed}
8687
(assoc (bidi/match-route routes uri-without-equal-in-path)
@@ -96,9 +97,19 @@
9697
(and equal-end-of-base64url (= handler :community) (:community-data route-params))
9798
(update-in [:route-params :community-data] #(str % equal-end-of-base64url))
9899

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

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

@@ -290,9 +301,13 @@
290301
(cb {:type (community-route-type route-params)
291302
:community-id (:community-id route-params)})
292303

293-
(= handler :community-chat)
304+
(and (= handler :community-chat) (:community-channel-id route-params) (:community-id route-params))
294305
(match-community-channel-async route-params cb)
295306

307+
(and (= handler :community-chat) (:community-id route-params))
308+
(cb {:type (community-route-type route-params)
309+
:community-id (:community-id route-params)})
310+
296311
;; NOTE: removed in `match-uri`, might need this in the future
297312
(= handler :wallet-account)
298313
(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)