summaryrefslogtreecommitdiff
path: root/desk/lib
diff options
context:
space:
mode:
Diffstat (limited to 'desk/lib')
-rw-r--r--desk/lib/constants.hoon1
-rw-r--r--desk/lib/json/nostr.hoon16
-rw-r--r--desk/lib/json/nostrill.hoon53
-rw-r--r--desk/lib/nostrill.hoon35
-rw-r--r--desk/lib/shim.hoon3
-rw-r--r--desk/lib/trill/feed.hoon51
6 files changed, 137 insertions, 22 deletions
diff --git a/desk/lib/constants.hoon b/desk/lib/constants.hoon
index c7f72b7..9beab32 100644
--- a/desk/lib/constants.hoon
+++ b/desk/lib/constants.hoon
@@ -1,3 +1,4 @@
|%
+++ feed-page-size 100
++ http-delay 3.000
--
diff --git a/desk/lib/json/nostr.hoon b/desk/lib/json/nostr.hoon
index 9c36eb0..6f93c1c 100644
--- a/desk/lib/json/nostr.hoon
+++ b/desk/lib/json/nostr.hoon
@@ -38,9 +38,11 @@
::
++ raw-event |= raw-event:sur
:: WTF nostr doesn't want the prefix on the pubkey
- =/ pubkeyt (scow:sr %ux pubkey)
+ =/ scw scow:sr
+ =/ pubkeyt (scw(min-chars 64) %ux pubkey)
?~ pubkeyt !!
- =/ pubkeyj [%s (crip t.pubkeyt)]
+ :: =/ pubkeyj [%s (crip t.pubkeyt)]
+ =/ pubkeyj [%s (crip pubkeyt)]
:- %a :~
[%n '0']
pubkeyj
@@ -51,13 +53,13 @@
==
++ event
|= e=event:sur ^- json
- =/ pubkeyt (scow:sr %ux pubkey.e)
- ?~ pubkeyt !!
- =/ pubkeyj [%s (crip t.pubkeyt)]
+ :: =/ pubkeyt (scow:sr %ux pubkey.e)
+ :: ?~ pubkeyt !!
+ :: =/ pubkeyj [%s (crip t.pubkeyt)]
%: pairs
id+(hex:en:common id.e)
- :: pubkey+(hex:en:common pubkey.e)
- pubkey+pubkeyj
+ pubkey+(hex:en:common pubkey.e)
+ :: pubkey+pubkeyj
sig+(hex:en:common sig.e)
['created_at' (numb created-at.e)]
kind+(numb kind.e)
diff --git a/desk/lib/json/nostrill.hoon b/desk/lib/json/nostrill.hoon
index 43f7708..bd34acc 100644
--- a/desk/lib/json/nostrill.hoon
+++ b/desk/lib/json/nostrill.hoon
@@ -6,6 +6,7 @@
|%
:: UI comms
++ state |= state-0:sur ^- json
+ %+ frond %state
%: pairs
relays+(en-relays relays)
key+(hex:en:common pub.i.keys)
@@ -38,27 +39,60 @@
++ en-profiles |= m=(map @ux user-meta:nsur)
%- pairs
%+ turn ~(tap by m) |= [key=@ux p=user-meta:nsur]
- :- (crip (scow:sr %ux key)) (user-meta:en:nostr p)
+ =/ jkey (hex:en:common key)
+ ?> ?=(%s -.jkey)
+ :- +.jkey (user-meta:en:nostr p)
++ enfollowing
|= m=(map @ux feed:feed)
^- json
%- pairs %+ turn ~(tap by m) |= [key=@ux f=feed:feed]
- :- (crip (scow:sr %ux key)) (feed:en:trill f)
+ =/ jkey (hex:en:common key)
+ ?> ?=(%s -.jkey)
+ :- +.jkey (feed:en:trill f)
++ engraph
|= m=(map @ux (set follow:sur))
^- json
%- pairs %+ turn ~(tap by m) |= [key=@ux s=(set follow:sur)]
- :- (crip (scow:sr %ux key))
- :- %a %+ turn ~(tap in s) |= f=follow:sur
- %- pairs
- :~ pubkey+(hex:en:common pubkey.f)
- name+s+name.f
- :- %relay ?~ relay.f ~ s+u.relay.f
- ==
+ =/ jkey (hex:en:common key)
+ ?> ?=(%s -.jkey)
+ :- +.jkey
+ :- %a %+ turn ~(tap in s) |= f=follow:sur
+ %- pairs
+ :~ pubkey+(hex:en:common pubkey.f)
+ name+s+name.f
+ :- %relay ?~ relay.f ~ s+u.relay.f
+ ==
+
+ :: ui facts
+ ++ fact |= f=fact:ui:sur ^- json
+ %+ frond %fact
+ %+ frond -.f
+ ?- -.f
+ %post (postfact +.f)
+ %enga (enga +.f)
+ ==
+ ++ postfact |= pf=post-fact:ui:sur ^- json
+ %+ frond -.pf
+ (post-wrapper +.pf)
+ ++ enga |= [pw=post-wrapper:sur reaction=*]
+ ^- json
+ ~
+ ++ post-wrapper |= p=post-wrapper:sur
+ %- pairs
+ :~ post+(poast:en:trill post.p)
+ ['nostrMeta' (nostr-meta nostr-meta.p)]
+ ==
+ ++ nostr-meta |= p=nostr-meta:sur
+ =| l=(list [@t json])
+ =. l ?~ pub.p l :_ l ['pubkey' (hex:en:common u.pub.p)]
+ =. l ?~ ev-id.p l :_ l ['eventId' (hex:en:common u.ev-id.p)]
+ =. l ?~ relay.p l :_ l ['relay' %s u.relay.p]
+ =. l ?~ pr.p l :_ l ['profile' (user-meta:en:nostr u.pr.p)]
+ %- pairs l
--
++ de
=, dejs-soft:format
@@ -94,7 +128,6 @@
==
++ de-post
%- ot :~
- pubkey+hex:de:common
content+so
==
++ de-rt
diff --git a/desk/lib/nostrill.hoon b/desk/lib/nostrill.hoon
index c7e940c..0570dbc 100644
--- a/desk/lib/nostrill.hoon
+++ b/desk/lib/nostrill.hoon
@@ -1,5 +1,5 @@
-/- post=trill-post, nsur=nostr, sur=nostrill
-/+ trill=trill-post, nostr, sr=sortug
+/- post=trill-post, nsur=nostr, sur=nostrill, gate=trill-gate
+/+ trill=trill-post, nostr, sr=sortug, jsonlib=json-nostrill
|%
::
++ default-state |= =bowl:gall ^- state:sur
@@ -47,9 +47,40 @@
signature
==
event
+
+++ event-to-post
+ |= [=event:nsur profile=(unit user-meta:nsur) relay=(unit @t)]
+ ^- post-wrapper:sur
+
+ =/ cl (tokenize:trill content.event)
+ =/ ts (from-unix:jikan:sr created-at.event)
+ =/ cm=content-map:post (init-content-map:trill cl ts)
+
+ :: TODO more about @ps and stuff
+ =/ p=post:post :*
+ id=ts
+ host=`@p`pubkey.event
+ author=`@p`pubkey.event
+ thread=ts
+ parent=~
+ children=~
+ contents=cm
+ read=*lock:gate
+ write=*lock:gate
+ *engagement:post
+ 0v0
+ *signature:post
+ tags=~
+ ==
+ =/ meta [(some pubkey.event) (some id.event) relay profile]
+ [p meta]
+
++ cards
|_ =bowl:gall
++ shim-binding ^- card:agent:gall
[%pass /binding %arvo %e %connect [~ /nostr-shim] dap.bowl]
+ ++ update-ui |= =fact:ui:sur ^- card:agent:gall
+ =/ jon (fact:en:jsonlib fact)
+ [%give %fact ~[/ui] %json !>(jon)]
--
--
diff --git a/desk/lib/shim.hoon b/desk/lib/shim.hoon
index 4afdf2b..f2e0b8a 100644
--- a/desk/lib/shim.hoon
+++ b/desk/lib/shim.hoon
@@ -105,9 +105,6 @@
=/ sub-id (gen-sub-id:nlib eny.bowl)
=/ kinds (silt ~[0])
=/ total=filter:nsur [~ `pubkeys `kinds ~ ~ ~ ~]
- =/ chunk (silt (scag 10 ~(tap in pubkeys)))
- =/ =filter:nsur [~ `chunk `kinds ~ ~ ~ ~]
- =. pending.state (~(put by pending.state) sub-id [total *filter:nsur])
=/ req=http-req:shim:nsur [relay http-delay:constants sub-id ~[total]]
=/ =card (send-http req)
:- :~(card) state
diff --git a/desk/lib/trill/feed.hoon b/desk/lib/trill/feed.hoon
new file mode 100644
index 0000000..c21feb3
--- /dev/null
+++ b/desk/lib/trill/feed.hoon
@@ -0,0 +1,51 @@
+/- feed=trill-feed, sur=nostrill
+/+ sr=sortug, constants
+|%
+++ latest-page |= f=feed:feed ^- fc:feed
+ =/ nodelist (tap:orm:feed f)
+ =/ subset (scag feed-page-size:constants nodelist)
+ ?~ subset [f ~ ~]
+ =/ start `id.i.subset
+ =/ rev (flop subset)
+ ?~ rev [f ~ ~]
+ =/ end `id.i.rev
+ =/ nf (gas:orm:feed *feed:feed subset)
+ [nf start end]
+::
+++ latest-page-nostr |= f=nostr-feed:sur ^- nfc:sur
+ =/ nodelist (tap:norm:sur f)
+ =/ subset (scag feed-page-size:constants nodelist)
+ ?~ subset [f ~ ~]
+ =/ start `id.i.subset
+ =/ rev (flop subset)
+ ?~ rev [f ~ ~]
+ =/ end `id.i.rev
+ =/ nf (gas:norm:sur *nostr-feed:sur subset)
+ [nf start end]
+::
+:: NOTE START IS OLD, END IS NEW
+
+++ subset
+|= [=fc:feed replies=? now=@da] ^- fc:feed
+ ?: ?&(?=(%~ start.fc) ?=(%~ end.fc)) (latest-page feed.fc)
+
+ =/ count feed-page-size:constants
+ =/ start ?~ start.fc 0 u.start.fc
+ =/ end ?~ end.fc now u.end.fc
+ =/ nodelist (tap:orm:feed feed.fc)
+
+ =/ threads %+ skim nodelist
+ |= [=id:post =post:post] ^- ?
+ ?. replies
+ ?&
+ ?= %~ parent.post
+ (lte id start) (gte id end)
+ ==
+ ?& (lte id start) (gte id end) ==
+ =/ thread-count (lent threads)
+ =/ result=(list [id:post post:post]) ?: newest (scag count threads) (flop (scag count (flop threads)))
+ =/ cursors=[(unit @da) (unit @da)] ?~ result [~ ~] ?~ threads [~ ~] :-
+ ?: .=((head result) (head threads)) ~ `id:(head result)
+ ?: .=((rear result) (rear threads)) ~ `id:(rear result)
+ [(gas:orm:feed *feed:feed result) -.cursors +.cursors]
+--