mirror of
https://github.com/unclebob/more-speech.git
synced 2024-09-30 10:30:56 +00:00
Hitting ^S in edit window actually composes and sends the event to the relay! WOOT!
This commit is contained in:
parent
6472e7ca9b
commit
0b1da7f1ca
@ -14,6 +14,7 @@
|
||||
(ns more-speech.core
|
||||
(:require [quil.core :as q]
|
||||
[quil.middleware :as m]
|
||||
[clojure.core.async :as async]
|
||||
[more-speech.nostr.events :as nostr]
|
||||
[more-speech.ui.widget :refer [draw-widget
|
||||
setup-widget
|
||||
@ -27,6 +28,7 @@
|
||||
[more-speech.nostr.protocol :as protocol]))
|
||||
|
||||
(def events (atom []))
|
||||
(def send-chan (async/chan))
|
||||
|
||||
(defn get-keys [state]
|
||||
(let [keys (read-string (slurp "private/keys"))
|
||||
@ -44,7 +46,8 @@
|
||||
application (map->application {:path [:application] :graphics graphics})
|
||||
application (setup-widget application {})
|
||||
state {:application application}
|
||||
state (get-keys state)]
|
||||
state (get-keys state)
|
||||
state (assoc state :send-chan send-chan)]
|
||||
(q/text-font bold)
|
||||
(setup-child-widgets application state)
|
||||
))
|
||||
@ -92,7 +95,7 @@
|
||||
:middleware [m/fun-mode]
|
||||
:on-close protocol/close-connection)
|
||||
;(reset! events (read-string (slurp "nostr-messages")))
|
||||
(protocol/get-events events)
|
||||
(protocol/get-events events send-chan)
|
||||
args
|
||||
)
|
||||
|
||||
|
@ -109,7 +109,6 @@
|
||||
"returns byte array of id given the clojure form of the body"
|
||||
[{:keys [pubkey created_at kind tags content]}]
|
||||
(let [id-event (json/write-str [0 pubkey created_at kind tags content])
|
||||
_ (println "id string:" id-event)
|
||||
id (ecc/sha-256 (.getBytes id-event StandardCharsets/UTF_8))]
|
||||
id)
|
||||
)
|
||||
|
@ -113,9 +113,7 @@
|
||||
|
||||
(def private-key (ecc/sha-256 (.getBytes "I am Bob.")))
|
||||
|
||||
(def terminator (async/chan))
|
||||
|
||||
(defn get-events [events]
|
||||
(defn get-events [events send-chan]
|
||||
(let [conn (connect-to-relay (get relays 0) events)
|
||||
id "more-speech"
|
||||
date (make-date "04/01/2022")
|
||||
@ -124,14 +122,20 @@
|
||||
(unsubscribe conn id)
|
||||
(subscribe conn id date)
|
||||
;(send-to conn ["EVENT" {:pubkey "2ef93f01cd2493e04235a6b87b10d3c4a74e2a7eb7c3caf168268f6af73314b5", :created_at 1649969311, :kind 1, :tags [], :content "Hello from more-speech.", :id "b05141aecb7d975ae7df861a13082d98ad76e9f46accc046ba221533877b69c6", :sig "e80411eee168aa620b035ce16622eda24d059859562276305a1c8900559b3bc5ae0505754e5d0f352891717eb34f4495771bcf11c80d01cdd19025a51e99979d"}])
|
||||
(async/<!! terminator)
|
||||
(loop [msg (async/<!! send-chan)]
|
||||
(condp = (first msg)
|
||||
:closed nil
|
||||
:event
|
||||
(do
|
||||
(send-to conn (second msg))
|
||||
(recur (async/<!! send-chan)))))
|
||||
(unsubscribe conn id)
|
||||
(.get (.sendClose conn WebSocket/NORMAL_CLOSURE "done"))
|
||||
(Thread/sleep 1000))
|
||||
(prn 'done)
|
||||
)
|
||||
|
||||
(defn close-connection [_state]
|
||||
(defn close-connection [state]
|
||||
(prn 'close-connection)
|
||||
(async/>!! terminator "bye")
|
||||
(async/>!! (:send-chan state) [:closed])
|
||||
)
|
||||
|
@ -5,7 +5,8 @@
|
||||
[more-speech.ui.config :as config]
|
||||
[clojure.spec.alpha :as s]
|
||||
[more-speech.nostr.events :as events]
|
||||
[clojure.string :as string]))
|
||||
[clojure.string :as string]
|
||||
[clojure.core.async :as async]))
|
||||
|
||||
(s/def ::text (and vector? (s/coll-of string?)))
|
||||
(s/def ::insertion-point (s/tuple [int? int?]))
|
||||
@ -141,6 +142,7 @@
|
||||
(prn 'send-message)
|
||||
(let [private-key (get-in state [:keys :private-key])
|
||||
text (string/join \newline (:text frame))
|
||||
event (events/compose-text-event private-key text)]
|
||||
(prn 'event event)
|
||||
state))
|
||||
event (events/compose-text-event private-key text)
|
||||
send-chan (:send-chan state)]
|
||||
(async/>!! send-chan [:event event])
|
||||
state))
|
||||
|
Loading…
Reference in New Issue
Block a user