init nostr with gniazdo

This commit is contained in:
Travis Shears 2025-08-18 09:39:23 +02:00
parent 2c3d3cef2f
commit 911f2f0330
3 changed files with 38 additions and 2 deletions

28
src/micro_blog/nostr.clj Normal file
View file

@ -0,0 +1,28 @@
(ns micro-blog.nostr
(:require
[gniazdo.core :as ws]
[cheshire.core :as json]
[micro-blog.config :refer [config]]))
;; :nostr-fetcher-npub "NOSTR_FETCHER_NPUB"
;; :nostr-id "NOSTR_ID"
;; :nostr-relay "NOSTR_RELAY"
(def socket (atom nil))
(defn connect []
(reset! socket
(ws/connect
(@config :nostr-relay)
:on-receive #(prn 'received %))))
(defn subscribe-to-author [pubkey]
(let [sub-id "sub-1"
filter {:kinds [1] :authors [pubkey] :limit 10}
msg (json/generate-string ["REQ" sub-id filter])]
(send-msg msg)))
(defn send-msg [msg]
(ws/send-msg @socket msg))
(defn close []
(ws/close @socket))