dm-hook: add root if nonexistent

This commit is contained in:
Liam Fitzgerald 2021-04-23 14:14:47 +10:00
parent 097bae6fb7
commit d490855aaa
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
2 changed files with 50 additions and 10 deletions

View File

@ -54,6 +54,26 @@
==
==
::
++ add-node
|= [=index:store =node:store]
^- update:store
:^ now.bowl %add-nodes [our.bowl %inbox]
(~(gas by *(map index:store node:store)) [index node] ~)
::
++ add-missing-root
|= =ship
^- (list card)
=/ =index:store
[ship ~]
?: (check-node-existence:gra [our.bowl %inbox] index) ~
=| =node:store
=: author.post.node our.bowl
index.post.node index
time-sent.post.node now.bowl
==
=/ =wire /dm/(scot %p ship)
(~(poke-our pass wire) %graph-store (update:cg:gra (add-node index node)))^~
::
++ outgoing-add
|= nodes=(map index:store node:store)
^- (list card)
@ -65,13 +85,12 @@
=/ =ship i.index
=/ =dock [ship %dm-hook]
=/ =wire /dm/(scot %p ship)
=; =cage
=/ =cage
(update:cg:gra (add-node index node))
%+ welp (add-missing-root ship)
:~ (~(poke pass wire) dock cage)
(~(poke-our pass wire) %graph-store cage)
==
%+ update:cg:gra now.bowl
:+ %add-nodes [our.bowl %inbox]
(~(gas by *(map index:store node:store)) [index node] ~)
::
++ incoming-add
|= nodes=(map index:store node:store)
@ -79,10 +98,10 @@
?> =(1 ~(wyt by nodes))
=* ship src.bowl
=/ =wire /dm/(scot %p ship)
:_ ~
%+ snoc (add-missing-root ship)
%+ ~(poke-our pass wire) %graph-store
%+ update:cg:gra now.bowl
:+ %add-nodes [ship %inbox]
:+ %add-nodes [our.bowl %inbox]
%- ~(gas by *(map index:store node:store))
%+ turn ~(tap by nodes)
|= [=index:store =node:store]

View File

@ -0,0 +1,21 @@
:: graph-store|add-post: add post to a graph
::
/- *graph-store
:- %say
|= $: [now=@da eny=@uvJ =beak]
[[him=ship contents=(list content) ~] ~]
==
=* our p.beak
=/ =post *post
=: author.post our
index.post ~[him now]
time-sent.post now
contents.post contents
==
::
:- %graph-update-1
^- update
:- now
:+ %add-nodes [our %inbox]
%- ~(gas by *(map index node))
~[[~[him now] [post [%empty ~]]]]