diff options
| author | polwex <polwex@sortug.com> | 2025-10-06 01:01:41 +0700 |
|---|---|---|
| committer | polwex <polwex@sortug.com> | 2025-10-06 01:01:41 +0700 |
| commit | c4b392a179048f936c062f5ffccc2bc25627e500 (patch) | |
| tree | 09be0904be8ec4d7ea52992ef7580d42ed0c28c1 /app/lib/nostrill | |
working
Diffstat (limited to 'app/lib/nostrill')
| -rw-r--r-- | app/lib/nostrill/comms.hoon | 92 | ||||
| -rw-r--r-- | app/lib/nostrill/follows.hoon | 90 |
2 files changed, 182 insertions, 0 deletions
diff --git a/app/lib/nostrill/comms.hoon b/app/lib/nostrill/comms.hoon new file mode 100644 index 0000000..5f9b0a9 --- /dev/null +++ b/app/lib/nostrill/comms.hoon @@ -0,0 +1,92 @@ +/- sur=nostrill, nsur=nostr, comms=nostrill-comms, feed=trill-feed +/+ js=json-nostr, sr=sortug,constants, gatelib=trill-gate, feedlib=trill-feed, jsonlib=json-nostrill +|_ [=state:sur =bowl:gall] +++ cast-poke + |= raw=* ^- poke:comms + ;; poke:comms raw +:: Req +++ handle-req |= =req:comms + ?- -.req + %feed handle-feed + %thread (handle-thread +.req) + == +++ handle-feed + =/ can (can-access:gatelib src.bowl lock.feed-perms.state bowl) + ?. can + :: TODO keep track of the requests at the feed-perms struct + =/ crd (res-poke [%ng 'not allowed']) + :_ state :~(crd) + :: + =/ lp latest-page:feedlib + =/ lp2 lp(count backlog.feed-perms.state) + =/ =fc:feed (lp2 feed.state) + =/ prof (~(get by profiles.state) [%urbit our.bowl]) + =/ crd (res-poke [%ok %feed fc prof]) + :_ state :~(crd) + +++ give-feed + |= pat=path + ~& give-feed=src.bowl + =/ can (can-access:gatelib src.bowl lock.feed-perms.state bowl) + ?. can + :: TODO keep track of the requests at the feed-perms struct + (res-fact [%ng 'not allowed'] pat) + :: + =/ lp latest-page:feedlib + =/ lp2 lp(count backlog.feed-perms.state) + =/ =fc:feed (lp2 feed.state) + =/ prof (~(get by profiles.state) [%urbit our.bowl]) + (res-fact [%ok %feed fc prof] pat) + + +++ give-ted |= [id=@ pat=path] + =/ ted (get:orm:feed feed.state id) + ?~ ted + (res-fact [%ng 'no such thread'] pat) + =/ can (can-access:gatelib src.bowl read.u.ted bowl) + ?. can + (res-fact [%ng 'not allowed'] pat) + :: + =/ fn (node-to-full:feedlib u.ted feed.state) + (res-fact [%ok %thread fn] pat) +:: +++ handle-thread |= id=@da + =/ ted (get:orm:feed feed.state id) + ?~ ted + =/ crd (res-poke [%ng 'no such thread']) + :_ state :~(crd) + =/ can (can-access:gatelib src.bowl read.u.ted bowl) + ?. can + =/ crd (res-poke [%ng 'not allowed']) + :_ state :~(crd) + :: + =/ fn (node-to-full:feedlib u.ted feed.state) + =/ crd (res-poke [%ok %thread fn]) + :_ state :~(crd) +:: res +++ handle-res |= =res:comms + `state +:: +++ res-poke |= =res:comms ^- card:agent:gall + =/ =poke:comms [%res res] + =/ cage [%noun !>(poke)] + [%pass /poke %agent [src.bowl dap.bowl] %poke cage] + +++ res-fact |= [=res:comms pat=path] ^- (list card:agent:gall) + =/ beg ?=([%beg *] pat) + =/ paths ~[pat] + ~& > giving-res-fact=pat + ?: beg :: for the thread that goes directly to the frontend + =/ jon (beg-res:en:jsonlib res) + =/ cage [%json !>(jon)] + =/ c1 [%give %fact paths cage] + =/ c2 [%give %kick paths ~] + :~(c1 c2) + :: for the follow flow + =/ cage [%noun !>([%init res])] + =/ c1 [%give %fact paths cage] + :~(c1) + + + +-- diff --git a/app/lib/nostrill/follows.hoon b/app/lib/nostrill/follows.hoon new file mode 100644 index 0000000..e4d04a6 --- /dev/null +++ b/app/lib/nostrill/follows.hoon @@ -0,0 +1,90 @@ +/- sur=nostrill, nsur=nostr, comms=nostrill-comms, feed=trill-feed +/+ lib=nostrill, js=json-nostr, shim, sr=sortug, constants, gatelib=trill-gate, feedlib=trill-feed, jsonlib=json-nostrill +|_ [=state:sur =bowl:gall] +++ handle-add |= =user:sur + ^- (quip card:agent:gall _state) + ?- -.user + %urbit =/ c (urbit-watch +.user) + :- :~(c) state + %nostr =/ shimm ~(. shim [state bowl]) + :: TODO now or on receival? + =. following.state (~(put by following.state) user *feed:feed) + =/ graph (~(get by follow-graph.state) [%urbit our.bowl]) + =/ follows ?~ graph (silt ~[user]) (~(put in u.graph) user) + =. follow-graph.state (~(put by follow-graph.state) [%urbit our.bowl] follows) + + =^ cards state (get-user-feed:shimm +.user) + [cards state] + == +++ handle-del |= =user:sur + ^- (quip card:agent:gall _state) + =. following.state (~(del by following.state) user) + =/ graph (~(get by follow-graph.state) [%urbit our.bowl]) + ?~ graph `state + =/ nset (~(del in u.graph) user) + =. follow-graph.state (~(put by follow-graph.state) [%urbit our.bowl] nset) + :_ state + =/ =fact:ui:sur [%fols %quit user] + =/ c1 (update-ui:cards:lib fact) + ?. ?=(%urbit -.user) :~(c1) + ~& >> leaving=user + =/ c2 (urbit-leave +.user) + :~(c1 c2) + +++ handle-follow-res |= =res:comms + ?- -.res + %ng :: bruh + `state + %ok + ?- -.p.res + %feed (handle-follow-ok [%urbit src.bowl] fc.+.p.res profile.+.p.res) + %thread `state + == + == +++ handle-refollow |= sip=@p + :_ state :_ ~ + :: (urbit-watch sip) + [%pass /follow %agent [sip dap.bowl] %watch /follow] + +++ handle-follow-ok |= [=user:sur =fc:feed profile=(unit user-meta:nsur)] + ^- (quip card:agent:gall _state) + =. following.state (~(put by following.state) user feed.fc) + =/ graph (~(get by follow-graph.state) [%urbit our.bowl]) + =/ follows ?~ graph (silt ~[user]) (~(put in u.graph) user) + =. follow-graph.state (~(put by follow-graph.state) [%urbit our.bowl] follows) + =. profiles.state ?~ profile profiles.state (~(put by profiles.state) user u.profile) + :_ state + =/ =fact:ui:sur [%fols %new [%urbit src.bowl] fc profile] + =/ c (update-ui:cards:lib fact) :~(c) + + +++ handle-kick-nack |= p=@p + ^- (quip card:agent:gall _state) + =. following.state (~(del by following.state) [%urbit p]) + =/ graph (~(get by follow-graph.state) [%urbit our.bowl]) + ?~ graph `state + =/ ngraph (~(del in u.graph) [%urbit p]) + =. follow-graph.state (~(put by follow-graph.state) [%urbit our.bowl] ngraph) + :_ state + =/ =fact:ui:sur [%fols %quit %urbit src.bowl] + =/ c (update-ui:cards:lib fact) :~(c) + + +++ urbit-leave |= sip=@p ^- card:agent:gall + [%pass /follow %agent [sip dap.bowl] %leave ~] + +++ urbit-watch |= sip=@p ^- card:agent:gall + [%pass /follow %agent [sip dap.bowl] %watch /follow] + +:: ++ res-fact |= =res:comms ^- (list card:agent:gall) +:: =/ paths ~[/beg/feed] +:: =/ =poke:comms [%res res] +:: ~& > giving-res-fact=res +:: =/ jon (beg-res:en:jsonlib res) +:: =/ cage [%json !>(jon)] +:: :~ +:: [%give %fact paths cage] +:: [%give %kick paths ~] +:: == + +-- |
