dev / templates / app-cljs-rooms / client / src / __NAME__ / social.cljs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;; The social side: presence to friends, live invite toasts, and the sealed
;; self-channel that carries the room list to devices which are never in a room
;; together.
;;
;; This is the ONLY namespace that requires the full kit; shadow-cljs.edn puts it
;; in its own :social module and scripts/build.mjs gates that the kit's engine
;; literal appears ONLY in that chunk. Loaded through shadow.lazy from
;; __NAME__.room, after the room is already live — it must never delay or break
;; the room.
(ns __NAME__.social
  (:require ["ardegazu-social-kit" :refer (attachSocial)]
            [__NAME__.app.rooms :as rooms]
            [__NAME__.app.store :as store]
            [__NAME__.app.ui :as ui]
            [__NAME__.config :as config]
            [__NAME__.i18n :as i18n :refer (tn)]
            [ardegazu.rooms.js :as j]
            [shadow.cljs.modern :refer (js-await)]))

(defn attach!
  "opts: js obj (net idBoot bridge store ui secret)."
  [opts]
  (let [net-obj (unchecked-get opts "net")
        id-boot (unchecked-get opts "idBoot")
        bridge (unchecked-get opts "bridge")
        st (unchecked-get opts "store")
        ui-obj (unchecked-get opts "ui")
        secret (unchecked-get opts "secret")
        last-rec (.lastRecord ^js bridge)]
    (js-await [agent (attachSocial
                      (j/ordered
                       "ns" config/NS
                       ;; the app id the suite knows you by — the salt's host part
                       "app" (aget (.split config/APP-SALT "/") 0)
                       "identity" (unchecked-get id-boot "identity")
                       "seed" (unchecked-get id-boot "seed")
                       "myName" (fn [] (store/my-name st))
                       "pubsub" (unchecked-get (unchecked-get (unchecked-get net-obj "libp2p") "services")
                                               "pubsub")
                       "soc" (when (j/truthy? last-rec) (unchecked-get last-rec "soc"))
                       "roomLink" (fn [] (str (.-origin js/location) (.-pathname js/location) "#" secret))
                       "t" i18n/t-kit
                       ;; room-list sync, second transport: the sealed
                       ;; self-channel fsync (mailbox-backed) reaches devices that
                       ;; never share a live room. Same fold + toast as the
                       ;; directed in-room roomsync in room.cljs.
                       "appState"
                       (j/ordered
                        "get" (fn [] (rooms/build-room-sync))
                        "apply" (fn [s]
                                  (try
                                    (let [n (rooms/merge-rooms s secret)]
                                      (when (pos? n) (ui/toast ui-obj (tn "toast.rooms-synced" n))))
                                    (catch :default _ nil))
                                  js/undefined))))]
      (do
        ;; any local list change (visit/rename/forget/merge) → debounced,
        ;; hash-gated self-sync deposit for this identity's other devices
        (when (j/truthy? agent)
          (rooms/set-on-rooms-changed (fn [] (.syncNow ^js agent) js/undefined)))
        js/undefined))))

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/dev.git