init nostr with gniazdo
This commit is contained in:
parent
2c3d3cef2f
commit
911f2f0330
3 changed files with 38 additions and 2 deletions
28
src/micro_blog/nostr.clj
Normal file
28
src/micro_blog/nostr.clj
Normal 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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue