Skip to content

Commit 99200d4

Browse files
committed
fix: add ulink support for p chat and com request back
blocking e2e test Signed-off-by: yqrashawn <[email protected]>
1 parent fe2272b commit 99200d4

File tree

1 file changed

+40
-29
lines changed

1 file changed

+40
-29
lines changed

src/status_im/router/core.cljs

+40-29
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030

3131
(def handled-schemes (set (into uri-schemes web-urls)))
3232

33+
(def group-chat-extractor
34+
{[#"(.*)" :params] {"" :group-chat
35+
"/" :group-chat}})
36+
3337
(def eip-extractor
3438
{#{[:prefix "-" :address]
3539
[:address]}
@@ -39,9 +43,13 @@
3943

4044
(def routes
4145
[""
42-
{handled-schemes {["c/" :community-data] :community
43-
["cc/" :chat-data] :community-chat
44-
["u/" :user-data] :user}
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}
4553
ethereum-scheme eip-extractor}])
4654

4755
(defn parse-query-params
@@ -58,8 +66,7 @@
5866

5967
(defn match-uri
6068
[uri]
61-
;;
62-
(let [;; bidi has trouble parse path with `=` in it extract `=` here and add back to parsed
69+
(let [ ;; bidi has trouble parse path with `=` in it extract `=` here and add back to parsed
6370
;; base64url regex based on https://datatracker.ietf.org/doc/html/rfc4648#section-5 may
6471
;; include invalid base64 (invalid length, length of any base64 encoded string must be a
6572
;; multiple of 4)
@@ -71,7 +78,7 @@
7178
(if equal-end-of-base64url (string/replace-first uri equal-end-of-base64url "") uri)
7279

7380
fragment (parse-fragment uri)
74-
ens? (ens/is-valid-eth-name? fragment)
81+
ens? (ens/is-valid-eth-name? fragment)
7582

7683
{:keys [handler route-params] :as parsed}
7784
(assoc (bidi/match-route routes uri-without-equal-in-path)
@@ -87,8 +94,8 @@
8794
(and equal-end-of-base64url (= handler :community) (:community-data route-params))
8895
(update-in [:route-params :community-data] #(str % equal-end-of-base64url))
8996

90-
(and equal-end-of-base64url (= handler :community-chat) (:chat-data route-params))
91-
(update-in [:route-params :chat-data] #(str % equal-end-of-base64url))
97+
(and fragment (= handler :community-chat) (:community-channel-id route-params))
98+
(assoc-in [:route-params :community-id] fragment)
9299

93100
(and equal-end-of-base64url (= handler :user) (:user-data route-params))
94101
(update-in [:route-params :user-data] #(str % equal-end-of-base64url))
@@ -174,6 +181,15 @@
174181
(cb {:type :private-chat
175182
:error :invalid-chat-id})))))
176183

184+
(defn match-community-channel-async
185+
[{:keys [community-channel-id community-id]} cb]
186+
(if (validators/valid-compressed-key? community-id)
187+
(native-module/deserialize-and-compress-key
188+
community-id
189+
#(cb {:type :community-chat :chat-id (str % community-channel-id)}))
190+
(cb {:type :community-chat
191+
:error :not-found})))
192+
177193
(defn match-browser
178194
[uri {:keys [domain]}]
179195
;; NOTE: We rebuild domain from original URI and matched domain
@@ -238,8 +254,8 @@
238254
:community))
239255

240256
(defn handle-uri
241-
[chain _chats uri cb]
242-
(let [{:keys [handler route-params]} (match-uri uri)]
257+
[chain chats uri cb]
258+
(let [{:keys [handler route-params query-params]} (match-uri uri)]
243259
(log/info "[router] uri " uri " matched " handler " with " route-params)
244260
(cond
245261

@@ -253,36 +269,31 @@
253269
(and (= handler :user) (:user-id route-params))
254270
(match-contact-async chain route-params cb)
255271

256-
;; ;; NOTE: removed in `match-uri`, might need this in the future
257-
;; (= handler :private-chat)
258-
;; (match-private-chat-async chain route-params cb)
272+
;; NOTE: removed in `match-uri`, might need this in the future
273+
(= handler :private-chat)
274+
(match-private-chat-async chain route-params cb)
259275

260-
;; ;; NOTE: removed in `match-uri`, might need this in the future
261-
;; (= handler :group-chat)
262-
;; (cb (match-group-chat chats query-params))
276+
;; NOTE: removed in `match-uri`, might need this in the future
277+
(= handler :group-chat)
278+
(cb (match-group-chat chats query-params))
263279

264280
(validators/valid-public-key? uri)
265281
(match-contact-async chain {:user-id uri} cb)
266282

267-
;; ;; NOTE: removed in `match-uri`, might need this in the future
268-
;; (= handler :community-requests)
269-
;; (cb {:type handler :community-id (:community-id route-params)})
283+
;; NOTE: removed in `match-uri`, might need this in the future
284+
(= handler :community-requests)
285+
(cb {:type handler :community-id (:community-id route-params)})
270286

271287
(and (= handler :community) (:community-id route-params))
272288
(cb {:type (community-route-type route-params)
273289
:community-id (:community-id route-params)})
274290

275-
;; ;; TODO: jump to community overview for now, should jump to community channel
276-
;; (and (= handler :community-chat) (:chat-id route-params))
277-
;; (cb {:type handler :chat-id (:chat-id route-params)})
291+
(= handler :community-chat)
292+
(match-community-channel-async route-params cb)
278293

279-
(and (= handler :community-chat) (:community-id route-params))
280-
(cb {:type (community-route-type route-params)
281-
:community-id (:community-id route-params)})
282-
283-
;; ;; NOTE: removed in `match-uri`, might need this in the future
284-
;; (= handler :wallet-account)
285-
;; (cb (match-wallet-account route-params))
294+
;; NOTE: removed in `match-uri`, might need this in the future
295+
(= handler :wallet-account)
296+
(cb (match-wallet-account route-params))
286297

287298
(address/address? uri)
288299
(cb (address->eip681 uri))

0 commit comments

Comments
 (0)