|
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]}
|
|
40 | 44 | (def routes
|
41 | 45 | [""
|
42 | 46 | {handled-schemes {["c/" :community-data] :community
|
43 |
| - ["cc/" :chat-data] :community-chat |
| 47 | + ["cc/" :chat-data] :community-channel |
| 48 | + ["ccm/" :chat-id] :community-chat |
| 49 | + ["p/" :chat-id] :private-chat |
| 50 | + ["cr/" :community-id] :community-requests |
| 51 | + "g/" group-chat-extractor |
| 52 | + ["wallet/" :account] :wallet-account |
44 | 53 | ["u/" :user-data] :user}
|
45 | 54 | ethereum-scheme eip-extractor}])
|
46 | 55 |
|
|
58 | 67 |
|
59 | 68 | (defn match-uri
|
60 | 69 | [uri]
|
61 |
| - ;; |
62 | 70 | (let [;; bidi has trouble parse path with `=` in it extract `=` here and add back to parsed
|
63 | 71 | ;; base64url regex based on https://datatracker.ietf.org/doc/html/rfc4648#section-5 may
|
64 | 72 | ;; include invalid base64 (invalid length, length of any base64 encoded string must be a
|
|
81 | 89 | ens?
|
82 | 90 | (assoc-in [:route-params :ens-name] fragment)
|
83 | 91 |
|
84 |
| - (and (or (= handler :community) (= handler :community-chat)) fragment) |
| 92 | + (and (or (= handler :community) (= handler :community-channel)) fragment) |
85 | 93 | (assoc-in [:route-params :community-id] fragment)
|
86 | 94 |
|
87 | 95 | (and equal-end-of-base64url (= handler :community) (:community-data route-params))
|
88 | 96 | (update-in [:route-params :community-data] #(str % equal-end-of-base64url))
|
89 | 97 |
|
90 |
| - (and equal-end-of-base64url (= handler :community-chat) (:chat-data route-params)) |
| 98 | + (and equal-end-of-base64url (= handler :community-channel) (:chat-data route-params)) |
91 | 99 | (update-in [:route-params :chat-data] #(str % equal-end-of-base64url))
|
92 | 100 |
|
93 | 101 | (and equal-end-of-base64url (= handler :user) (:user-data route-params))
|
|
238 | 246 | :community))
|
239 | 247 |
|
240 | 248 | (defn handle-uri
|
241 |
| - [chain _chats uri cb] |
242 |
| - (let [{:keys [handler route-params]} (match-uri uri)] |
| 249 | + [chain chats uri cb] |
| 250 | + (let [{:keys [handler route-params query-params]} (match-uri uri)] |
243 | 251 | (log/info "[router] uri " uri " matched " handler " with " route-params)
|
244 | 252 | (cond
|
245 | 253 |
|
|
253 | 261 | (and (= handler :user) (:user-id route-params))
|
254 | 262 | (match-contact-async chain route-params cb)
|
255 | 263 |
|
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) |
| 264 | + ;; NOTE: removed in `match-uri`, might need this in the future |
| 265 | + (= handler :private-chat) |
| 266 | + (match-private-chat-async chain route-params cb) |
259 | 267 |
|
260 |
| - ;; ;; NOTE: removed in `match-uri`, might need this in the future |
261 |
| - ;; (= handler :group-chat) |
262 |
| - ;; (cb (match-group-chat chats query-params)) |
| 268 | + ;; NOTE: removed in `match-uri`, might need this in the future |
| 269 | + (= handler :group-chat) |
| 270 | + (cb (match-group-chat chats query-params)) |
263 | 271 |
|
264 | 272 | (validators/valid-public-key? uri)
|
265 | 273 | (match-contact-async chain {:user-id uri} cb)
|
266 | 274 |
|
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)}) |
| 275 | + ;; NOTE: removed in `match-uri`, might need this in the future |
| 276 | + (= handler :community-requests) |
| 277 | + (cb {:type handler :community-id (:community-id route-params)}) |
270 | 278 |
|
271 | 279 | (and (= handler :community) (:community-id route-params))
|
272 | 280 | (cb {:type (community-route-type route-params)
|
273 | 281 | :community-id (:community-id route-params)})
|
274 | 282 |
|
275 | 283 | ;; ;; TODO: jump to community overview for now, should jump to community channel
|
276 |
| - ;; (and (= handler :community-chat) (:chat-id route-params)) |
| 284 | + ;; (and (= handler :community-channel) (:chat-id route-params)) |
277 | 285 | ;; (cb {:type handler :chat-id (:chat-id route-params)})
|
278 | 286 |
|
279 |
| - (and (= handler :community-chat) (:community-id route-params)) |
| 287 | + (= handler :community-chat) |
| 288 | + (cb {:type handler :chat-id (:chat-id route-params)}) |
| 289 | + |
| 290 | + (and (= handler :community-channel) (:community-id route-params)) |
280 | 291 | (cb {:type (community-route-type route-params)
|
281 | 292 | :community-id (:community-id route-params)})
|
282 | 293 |
|
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