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

View file

@ -15,7 +15,11 @@
;; json
cheshire/cheshire {:mvn/version "6.0.0"}
;; metosin/muuntaja {:mvn/version "0.6.11"}
org.clojure/clojure {:mvn/version "1.12.1"}}
org.clojure/clojure {:mvn/version "1.12.1"}
;; websockets
stylefruits/gniazdo {:mvn/version "1.2.2"}
;; hato/hato {:mvn/version "1.0.0"}
}
:aliases
{;; Run with clj -T:build function-in-build

View file

@ -8,7 +8,11 @@
:mastodon-host "MASTODON_BASE_URL"
:mastodon-account-id "MASTODON_ACCOUNT_ID"
:api-host "API_HOST"
:api-port "API_PORT"})
:api-port "API_PORT"
:nostr-fetcher-npub "NOSTR_FETCHER_NPUB"
:nostr-id "NOSTR_ID"
:nostr-relay "NOSTR_RELAY"
})
(defn- load-config []
(merge (read-string (slurp "config.edn"))

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))