summaryrefslogtreecommitdiff
path: root/backupdesk/app
diff options
context:
space:
mode:
Diffstat (limited to 'backupdesk/app')
-rw-r--r--backupdesk/app/nostrill.hoon197
1 files changed, 197 insertions, 0 deletions
diff --git a/backupdesk/app/nostrill.hoon b/backupdesk/app/nostrill.hoon
new file mode 100644
index 0000000..4dd6ae5
--- /dev/null
+++ b/backupdesk/app/nostrill.hoon
@@ -0,0 +1,197 @@
+/- sur=nostrill, nsur=nostr
+/+ lib=nostrill, nlib=nostr, sr=sortug,
+ shim, dbug, muta=nostril-mutations, jsonlib=json-nostrill,
+ trill=trill-post
+/= web /web/router
+|%
++$ versioned-state $%(state-0:sur)
+--
+=| versioned-state
+=* state -
+%- agent:dbug
+^- agent:gall
+|_ =bowl:gall
++* this .
+ rout ~(. router:web [state bowl])
+ cards ~(. cards:lib bowl)
+ mutat ~(. muta [state bowl])
+ shimm ~(. shim [state bowl])
+++ on-init
+ ^- (quip card:agent:gall agent:gall)
+ =/ default (default-state:lib bowl)
+ :_ this(state default)
+ :~ shim-binding:cards
+ ==
+::
+++ on-save
+ ^- vase
+ !>(state)
+::
+++ on-load
+ |~ old-state=vase
+ ^- (quip card:agent:gall agent:gall)
+ =/ old-state !<(versioned-state old-state)
+ ?- -.old-state
+ %0 `this(state old-state)
+ ==
+::
+++ on-poke
+ |~ [=mark =vase]
+ ^- (quip card:agent:gall agent:gall)
+ |^
+ ?+ mark `this
+ %noun debug
+ %json on-ui
+ %handle-http-request handle-shim
+ ==
+ :: handling shim events
+ ++ handle-shim
+ =/ order !<(order:web vase)
+ :: ~& request.req.order
+ ?: .=(url.request.req.order '/nostr-shim')
+ =/ msg (parse-msg:shim order)
+ ?~ msg `this
+ (handle-shim-msg:mutat u.msg)
+
+ ::
+ :_ this (rout:rout order)
+
+ ::
+ ++ on-ui
+ =/ jon=json !<(json vase)
+ ~& > on-ui-jon=jon
+ =/ upoke=(unit poke:ui:sur) (ui:de:jsonlib jon)
+ ?~ upoke ~& bad-ui-poke=jon `this
+ ?- -.u.upoke
+ %keys handle-cycle-keys
+ %fols (handle-fols +.u.upoke)
+ %prof (handle-prof +.u.upoke)
+ %post (handle-post +.u.upoke)
+ %rela (handle-rela +.u.upoke)
+ ==
+ ++ handle-cycle-keys
+ =/ ks (gen-keys:nlib eny.bowl)
+ =. keys [ks keys]
+ :: =/ nkeys keys(i ks, t `(list keys:nsur)`keys)
+ :: :: =. keys nkeys
+ ~& new-keys=keys
+ `this
+
+ ++ handle-post |= poke=post-poke:ui:sur
+ ?- -.poke
+ %add
+ =/ sp (build-sp:trill our.bowl our.bowl content.poke)
+ =/ p (build-post:trill now.bowl pubkey.poke sp)
+ =. state (add-to-feed:mutat p)
+ `this
+ %rt `this
+ %del `this
+ ==
+ ++ handle-fols |= poke=fols-poke:ui:sur
+ `this
+ ++ handle-prof |= poke=prof-poke:ui:sur
+ ?- -.poke
+ %add
+ =. profiles (~(put by profiles) +<.poke +>.poke)
+ `this
+ %del
+ =. profiles (~(del by profiles) +.poke)
+ `this
+ ==
+ ++ handle-rela |= poke=relay-poke:ui:sur
+ ?- -.poke
+ %send
+ =/ upoast (get-poast:mutat host.poke id.poke)
+ ?~ upoast `this
+ =/ event (post-to-event:lib i.keys eny.bowl u.upoast)
+ =/ req=bulk-req:shim:nsur [relays.poke %event event]
+ =/ cards :~((send:shimm req))
+ [cards this]
+ ==
+
+
+ ::
+ ++ debug
+ =/ noun !<(* vase)
+ ?+ noun `this
+ %wtf
+ =/ lol=(unit @) ~
+ =/ l ~| "wtf" (need lol)
+ `this
+ %genkey
+ =/ keys (gen-keys:nlib eny.bowl)
+ ~& keys=keys
+ `this
+ %printkey
+ =/ key i.keys
+ ~& pub=(scow:sr %ux -.key)
+ ~& priv=(scow:sr %ux +.key)
+ `this
+ %feed
+ =/ lol debug-own-feed:mutat
+ `this
+ %nstats
+ ~& nostr-feed=~(wyt by nostr-feed)
+ ~& profiles=~(wyt in ~(key by profiles))
+ =/ lol (print-relay-stats:lib relays)
+
+ `this
+ %rt :: relay test
+ =^ cards state get-posts:shimm
+ [cards this]
+ %rt0
+ =/ ids
+ %+ roll (tap:norm:sur nostr-feed) |= [[@ ev=event:nsur] acc=[(set @ux) (set @ux)]]
+ ?. .=(kind.ev 1) acc
+ %= acc
+ - (~(put in -.acc) id.ev)
+ + (~(put in +.acc) pubkey.ev)
+ ==
+ =/ sids (silt (scag 10 ~(tap in +.ids)))
+ =^ cards state (get-profiles:shimm sids)
+ :: (get-profiles:shimm +.ids)
+ :: (get-engagement:shimm -.ids)
+ [cards this]
+ ==
+ ::
+ --
+::
+++ on-watch
+|= =(pole knot)
+ ?> .=(our.bowl src.bowl)
+ ?+ pole !!
+ [%ui ~]
+ :_ this
+ =/ jon (state:en:jsonlib state)
+ [%give %fact ~ [%json !>(jon)]]^~
+ ==
+::
+++ on-leave
+ |~ =(pole knot)
+ ^- (quip card:agent:gall agent:gall)
+ `this
+::
+++ on-peek
+ |~ =(pole knot)
+ ^- (unit (unit cage))
+ ~& > on-peek=pole
+ ?+ pole ~
+ [%j %feed rest=*] ~
+ [%j %post rest=*] ~
+ ==
+::
+++ on-agent
+ |~ [wire sign:agent:gall]
+ ^- (quip card:agent:gall agent:gall)
+ `this
+::
+++ on-arvo
+ |~ [wire =sign-arvo]
+ ^- (quip card:agent:gall agent:gall)
+ `this
+::
+++ on-fail
+ |~ [term tang]
+ ^- (quip card:agent:gall agent:gall)
+ `this
+--