summaryrefslogtreecommitdiff
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/json/common.hoon2
-rw-r--r--app/lib/json/nostr.hoon72
-rw-r--r--app/lib/mutations/nostr.hoon18
-rw-r--r--app/lib/nostr/req.hoon19
-rw-r--r--app/lib/websockets.hoon14
5 files changed, 123 insertions, 2 deletions
diff --git a/app/lib/json/common.hoon b/app/lib/json/common.hoon
index 0ed54cd..97513cb 100644
--- a/app/lib/json/common.hoon
+++ b/app/lib/json/common.hoon
@@ -22,6 +22,8 @@
=/ atom=(unit @) (slaw:sr %ux p.jon)
?~ atom ~
atom
+ ++ du |= jon=json ^- (unit @da)
+ (cu from-unix:chrono:userlib ni)
++ se |= aur=@tas |= jon=json
?. ?=(%s -.jon) ~
(slaw aur p.jon)
diff --git a/app/lib/json/nostr.hoon b/app/lib/json/nostr.hoon
index cb10c1d..8695a23 100644
--- a/app/lib/json/nostr.hoon
+++ b/app/lib/json/nostr.hoon
@@ -21,7 +21,7 @@
filters+a+(turn fs filter)
~
==
- ++ req |= =req:shim:sur ^- json
+ ++ req |= req=client-msg:sur ^- json
=/ en-ev event
:- %a :- s+(crip (cuss (trip -.req)))
?- -.req
@@ -107,6 +107,18 @@
other+o+other.meta
~
==
+ ++ relay-msg |= msg=relay-msg:sur ^- json
+ =/ head [%s -.msg]
+ :- %a :- head
+ ?- -.msg
+ %event ~[[%s sub-id.msg] (event event.msg)]
+ %ok ~[(hex:en:common id.msg) [%b accepted.msg] [%s msg.msg]]
+ %eose ~[[%s sub-id.msg]]
+ %closed ~[[%s sub-id.msg]]
+ %notice ~[[%s msg.msg]]
+ %auth ~[[%s challenge.msg]]
+ %error ~
+ ==
--
++ de
=, dejs-soft:format
@@ -131,7 +143,63 @@
notice+so
error+so
==
-
+ ++ client-msg
+ |= jon=json ^- (unit client-msg:sur)
+ ?. ?=(%a -.jon) ~
+ ?~ p.jon ~
+ =/ head i.p.jon
+ ?~ t.p.jon ~
+ =/ second i.t.p.jon
+ ?. ?=(%s -.head) ~
+ :: TODO make sure they're always caps
+ ?+ p.head ~
+ %'EVENT' `[%event ((event second))]
+ %'REQ' `[%req (so second) (turn t.t.p.jon filter)]
+ %'CLOSE' `[%close (so second)]
+ %'AUTH' [%auth (event second)]
+ ==
+ ++ filter |= jon=json ^- (unit filter:sur)
+ ?. ?=(%o -.jon) ~
+ =/ f *filter:sur
+ =/ entries ~(tap by p.jon)
+ |- ?~ entries `f
+ =/ entry=[@t json] i.entries
+ =. f
+ ?: .=('ids' -.entry)
+ =/ vl (ar +.entry hex:de:common)
+ ?~ vl f
+ =/ values (silt u.vl)
+ f(ids `values)
+ ?: .=('authors' -.entry)
+ =/ vl (ar +.entry hex:de:common)
+ ?~ vl f
+ =/ values (silt u.vl)
+ f(authors `values)
+ ?: .=('kinds' -.entry)
+ =/ vl (ar +.entry ud:de:common)
+ ?~ vl f
+ =/ values (silt u.vl)
+ f(kinds `values)
+ ?: .=('limit' -.entry)
+ =/ value (ni +.entry)
+ f(limit value)
+ ?: .=('since' -.entry)
+ =/ value (du:de:common +.entry)
+ f(since value)
+ ?: .=('until' -.entry)
+ =/ value (du:de:common +.entry)
+ f(until value)
+ :: anything else is a tag
+ =/ ctags ?~ tags.f *(map @t (set @t)) u.tags.f
+ =/ vl (ar +.entry so)
+ ?~ vl f
+ =/ values (silt u.vl)
+ =/ ntags (~(put by ctags) -.entry values)
+ f(tags ntags)
+ $(entries t.entries)
+
+
+
:: | { event: { subscription_id: string; event: NostrEvent } }
:: | { ok: { event_id: string; accepted: boolean; message: string } }
diff --git a/app/lib/mutations/nostr.hoon b/app/lib/mutations/nostr.hoon
index 2c6acd5..96ea6c6 100644
--- a/app/lib/mutations/nostr.hoon
+++ b/app/lib/mutations/nostr.hoon
@@ -3,6 +3,9 @@
/+ appjs=json-nostrill,
lib=nostrill,
+ nlib=nostr,
+ nreq=nostr-req,
+ server,
njs=json-nostr,
postlib=trill-post,
shim,
@@ -11,6 +14,21 @@
|_ [=state:sur =bowl:gall]
+$ card card:agent:gall
:: events
+++ handle-client-event |= [wid=@ =event:nsur] ^- (quip card _state)
+ ~& handling-client-event=event
+ =. nostr-feed.state (put:norm:sur nostr-feed.state created-at.event event)
+ =/ profile (~(get by profiles.state [%nostr author.event]))
+ :: TODO save if we're following?
+ :: =/ pw (event-to-post:nlib event profile)
+ =/ response (ok-client-event event .n 'we\'re full')
+ =/ cs (ws-response:nreq response)
+ [cs state]
+ :: =/ l events.state
+ :: =| cards=(list card:agent:gall)
+ :: |- ?~ l [cards state]
+ :: =/ n (event-parsing i.l)
+ :: $(cards -.n, state +.n, l t.l)
+
++ process-events ^- (quip card _state)
:: =/ l events.state
:: =| cards=(list card:agent:gall)
diff --git a/app/lib/nostr/req.hoon b/app/lib/nostr/req.hoon
new file mode 100644
index 0000000..ce566bc
--- /dev/null
+++ b/app/lib/nostr/req.hoon
@@ -0,0 +1,19 @@
+/- sur=nostr
+/+ js=json-nostr, sr=sortug,
+ lib=nostr,
+ server,
+ ws=websockets
+|%
+++ parse-client-msg
+ |= jon=json ^- (unit client-msg:nsur)
+ (client-msg:de:js jon)
+++ ok-client-event |= [=event:nsur ok=? msg=@t]
+ ^- relay-msg
+ [%ok id.event ok msg]
+++ ws-response
+ |= msg=relay-msg:sur ^- (list card:agent:gall)
+ =/ jon (relay-msg:en:js msg)
+ =/ octs (json-to-octs:server jon)
+ =/ res-event=websocket-event:eyre [%message 1 `octs]
+ (give-ws-payload:ws wid res-event)
+--
diff --git a/app/lib/websockets.hoon b/app/lib/websockets.hoon
new file mode 100644
index 0000000..9faea96
--- /dev/null
+++ b/app/lib/websockets.hoon
@@ -0,0 +1,14 @@
+|%
+ ++ give-ws-payload
+ |= [wid=@ event=websocket-event:eyre]
+ ^- (list card:agent:gall)
+ =/ =cage
+ [%websocket-response !>([wid event])]
+ =/ wsid (scot %ud wid)
+ :~ [%give %fact ~[/websocket-server/[wsid]] cage]
+ ==
+ ++ accept-handshake |= wid=@
+ =/ response [%accept ~]
+ (give-ws-payload wid response)
+
+--