|
30 | 30 |
|
31 | 31 | (def handled-schemes (set (into uri-schemes web-urls)))
|
32 | 32 |
|
| 33 | +(def group-chat-extractor |
| 34 | + {[#"(.*)" :params] {"" :group-chat |
| 35 | + "/" :group-chat}}) |
| 36 | + |
33 | 37 | (def eip-extractor
|
34 | 38 | {#{[:prefix "-" :address]
|
35 | 39 | [:address]}
|
|
39 | 43 |
|
40 | 44 | (def routes
|
41 | 45 | [""
|
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} |
45 | 53 | ethereum-scheme eip-extractor}])
|
46 | 54 |
|
47 | 55 | (defn parse-query-params
|
|
58 | 66 |
|
59 | 67 | (defn match-uri
|
60 | 68 | [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 |
63 | 70 | ;; base64url regex based on https://datatracker.ietf.org/doc/html/rfc4648#section-5 may
|
64 | 71 | ;; include invalid base64 (invalid length, length of any base64 encoded string must be a
|
65 | 72 | ;; multiple of 4)
|
|
71 | 78 | (if equal-end-of-base64url (string/replace-first uri equal-end-of-base64url "") uri)
|
72 | 79 |
|
73 | 80 | fragment (parse-fragment uri)
|
74 |
| - ens? (ens/is-valid-eth-name? fragment) |
| 81 | + ens? (ens/is-valid-eth-name? fragment) |
75 | 82 |
|
76 | 83 | {:keys [handler route-params] :as parsed}
|
77 | 84 | (assoc (bidi/match-route routes uri-without-equal-in-path)
|
|
87 | 94 | (and equal-end-of-base64url (= handler :community) (:community-data route-params))
|
88 | 95 | (update-in [:route-params :community-data] #(str % equal-end-of-base64url))
|
89 | 96 |
|
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) |
92 | 99 |
|
93 | 100 | (and equal-end-of-base64url (= handler :user) (:user-data route-params))
|
94 | 101 | (update-in [:route-params :user-data] #(str % equal-end-of-base64url))
|
|
174 | 181 | (cb {:type :private-chat
|
175 | 182 | :error :invalid-chat-id})))))
|
176 | 183 |
|
| 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 | + |
177 | 193 | (defn match-browser
|
178 | 194 | [uri {:keys [domain]}]
|
179 | 195 | ;; NOTE: We rebuild domain from original URI and matched domain
|
|
238 | 254 | :community))
|
239 | 255 |
|
240 | 256 | (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)] |
243 | 259 | (log/info "[router] uri " uri " matched " handler " with " route-params)
|
244 | 260 | (cond
|
245 | 261 |
|
|
253 | 269 | (and (= handler :user) (:user-id route-params))
|
254 | 270 | (match-contact-async chain route-params cb)
|
255 | 271 |
|
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) |
259 | 275 |
|
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)) |
263 | 279 |
|
264 | 280 | (validators/valid-public-key? uri)
|
265 | 281 | (match-contact-async chain {:user-id uri} cb)
|
266 | 282 |
|
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)}) |
270 | 286 |
|
271 | 287 | (and (= handler :community) (:community-id route-params))
|
272 | 288 | (cb {:type (community-route-type route-params)
|
273 | 289 | :community-id (:community-id route-params)})
|
274 | 290 |
|
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) |
278 | 293 |
|
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)) |
286 | 297 |
|
287 | 298 | (address/address? uri)
|
288 | 299 | (cb (address->eip681 uri))
|
|
0 commit comments