From 96d2906edce45efa65106aad1cb11537adf5afcd Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 18 Aug 2020 13:32:04 -0400 Subject: [PATCH 01/43] link: graph validator compiles and runs --- pkg/arvo/mar/graph/validator/link.hoon | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 pkg/arvo/mar/graph/validator/link.hoon diff --git a/pkg/arvo/mar/graph/validator/link.hoon b/pkg/arvo/mar/graph/validator/link.hoon new file mode 100644 index 000000000..006feda37 --- /dev/null +++ b/pkg/arvo/mar/graph/validator/link.hoon @@ -0,0 +1,27 @@ +/- *post +|_ i=indexed-post +++ grow + |% + ++ noun i + -- +++ grab + |% + ++ noun + |= p=* + =/ ip ;;(indexed-post p) + ?+ index.p.ip ~|(index+index.p.ip !!) + :: top-level link post + :: + [@ ~] + ?> ?=([[%text @] [%url @] [%text @] ~] contents.p.ip) + ip + :: + :: comment on link post + :: + [@ @ ~] + ?> ?=([[%text @] ~] contents.p.ip) + ip + == + -- +++ grad %noun +-- From dd2bae9320530ae564982d690ab268fc93f65db6 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 18 Aug 2020 15:41:24 -0400 Subject: [PATCH 02/43] links: data migration compiles; untested and still needs subscription migration --- pkg/arvo/app/link-store.hoon | 481 +++++-------------------- pkg/arvo/mar/graph/validator/link.hoon | 6 +- 2 files changed, 85 insertions(+), 402 deletions(-) diff --git a/pkg/arvo/app/link-store.hoon b/pkg/arvo/app/link-store.hoon index fed3d1206..0253b413f 100644 --- a/pkg/arvo/app/link-store.hoon +++ b/pkg/arvo/app/link-store.hoon @@ -50,10 +50,12 @@ :: ? :: /seen/wood-url/some-path have we seen this here :: -/- *link -/+ store=link-store, default-agent, verb, dbug +/- *link, gra=graph-store, *resource +/+ store=link-store, graph-store, default-agent, verb, dbug :: |% ++$ state-any $%(state-1 state-0) ++$ state-1 [%1 ~] +$ state-0 $: %0 by-group=(map path links) @@ -76,414 +78,95 @@ +$ card card:agent:gall -- :: -=| state-0 +=| state-1 =* state - :: %- agent:dbug %+ verb | ^- agent:gall -=< - |_ =bowl:gall - +* this . - do ~(. +> bowl) - def ~(. (default-agent this %|) bowl) - :: - ++ on-init on-init:def - ++ on-save !>(state) - ++ on-load - |= old=vase - ^- (quip card _this) - [~ this(state !<(state-0 old))] - :: - ++ on-poke - |= [=mark =vase] - ^- (quip card _this) - ?> (team:title [our src]:bowl) ::TODO /lib/store - =^ cards state - ?+ mark (on-poke:def mark vase) - ::TODO move json conversion into mark once mark performance improves - %json (do-action:do (action:dejs:store !<(json vase))) - %link-action (do-action:do !<(action:store vase)) - == - [cards this] - :: - ++ on-peek - |= =path - ^- (unit (unit cage)) - ?+ path (on-peek:def path) - [%y ?(%local-pages %submissions) ~] - ``noun+!>(~(key by by-group)) - :: - [%x %local-pages *] - ``noun+!>((get-local-pages:do t.t.path)) - :: - [%x %submissions *] - ``noun+!>((get-submissions:do t.t.path)) - :: - [%y ?(%annotations %discussions) *] - =/ [spath=^path surl=url] - (break-discussion-path:store t.t.path) - =- ``noun+!>(-) - :: - ?: =(~ surl) - :: no url, provide urls that have comments - :: - ^- (set url) - ?~ spath - :: no path, find urls accross all paths - :: - %- ~(rep by discussions) - |= [[* discussions=(map url discussion)] urls=(set url)] - %- ~(uni in urls) - ~(key by discussions) - :: specified path, find urls for that specific path - :: - %~ key by - (~(gut by discussions) spath *(map url *)) - :: specified url and path, nothing to list here - :: - ?^ spath !! - :: no path, find paths with comments for this url - :: - ^- (set ^path) - %- ~(rep by discussions) - |= [[=^path urls=(map url discussion)] paths=(set ^path)] - ?. (~(has by urls) surl) paths - (~(put in paths) path) - :: - [%x %annotations *] - ``noun+!>((get-annotations:do t.t.path)) - :: - [%x %discussions *] - ``noun+!>((get-discussions:do t.t.path)) - :: - [%x %seen @ ^] - ``noun+!>((is-seen:do t.t.path)) - :: - [%x %unseen ~] - ``noun+!>(get-all-unseen:do) - :: - [%x %unseen ^] - ``noun+!>((get-unseen:do t.t.path)) - == - :: - ++ on-watch - |= =path - ^- (quip card _this) - ?> (team:title [our src]:bowl) ::TODO /lib/store - :_ this - |^ ?+ path (on-watch:def path) - [%local-pages *] - %+ give %link-initial - ^- initial:store - [%local-pages (get-local-pages:do t.path)] - :: - [%submissions *] - %+ give %link-initial - ^- initial:store - [%submissions (get-submissions:do t.path)] - :: - [%annotations *] - %+ give %link-initial - ^- initial:store - [%annotations (get-annotations:do t.path)] - :: - [%discussions *] - %+ give %link-initial - ^- initial:store - [%discussions (get-discussions:do t.path)] - :: - [%seen ~] - ~ - == - :: - ++ give - |* [=mark =noun] - ^- (list card) - [%give %fact ~ mark !>(noun)]~ - :: - ++ give-single - |* [=mark =noun] - ^- card - [%give %fact ~ mark !>(noun)] - -- - :: - ++ on-leave on-leave:def - ++ on-agent on-agent:def - ++ on-arvo on-arvo:def - ++ on-fail on-fail:def - -- -:: |_ =bowl:gall ++* this . + do ~(. +> bowl) + def ~(. (default-agent this %|) bowl) :: -:: writing -:: -++ do-action - |= =action:store - ^- (quip card _state) - ?- -.action - %save (save-page +.action) - %note (note-note +.action) - %seen (seen-submission +.action) +++ on-init on-init:def +++ on-save !>(state) +++ on-load + |= old=vase + ^- (quip card _this) + =/ s !<(state-any old) + ?: ?=(%1 -.s) + [~ this(state s)] :: - %hear (hear-submission +.action) - %read (read-comment +.action) + :_ this(state *state-1) + =/ orm orm:graph-store + |^ ^- (list card) + %+ murn ~(tap by by-group.s) + |= [=path =links] + ^- (unit card) + ?. ?=([@ @ *] path) + (on-bad-path path links) + :- ~ + %+ add-graph `resource`[(slav %p i.path) i.t.path] + ^- graph:gra + %+ gas:orm ~ + =/ comments (~(gut by discussions.s) path *(map url discussion)) + %+ turn submissions.links + |= sub=submission + ^- [atom node:gra] + :- time.sub + =/ contents ~[text+title.sub url+url.sub] + =/ parent-hash `@ux`(sham ~ ship.sub time.sub contents) + :- ^- post:gra + :* author=ship.sub + index=~[time.sub] + time-sent=time.sub + contents + hash=`parent-hash + signatures=~ + == + ^- internal-graph:gra + =/ dis (~(get by comments) url.sub) + ?~ dis + [%empty ~] + :- %graph + ^- graph:gra + %+ gas:orm ~ + %+ turn comments.u.dis + |= [=ship =time udon=@t] + ^- [atom node:gra] + :- time + :_ `internal-graph:gra`[%empty ~] + =/ contents ~[text+udon] + :* author=ship + index=~[time.sub time] + time-sent=time + contents + hash=``@ux`(sham `parent-hash ship time contents) + signatures=~ == -:: +save-page: save a page ourselves -:: -++ save-page - |= [=path title=@t =url] - ^- (quip card _state) - ?< |(=(~ path) =(~ title) =(~ url)) - :: add page to group ours :: - =/ =links (~(gut by by-group) path *links) - =/ =page [title url now.bowl] - =. ours.links [page ours.links] - =. by-group (~(put by by-group) path links) - :: do generic submission logic + ++ on-bad-path + |= [=path =links] + ^- (unit card) + ~| discarding-malformed-links+[path links] + ~ :: - =^ submission-cards state - (hear-submission path [our.bowl page]) - :: mark page as seen (because we submitted it ourselves) - :: - =^ seen-cards state - (seen-submission path `url) - :: send updates to subscribers - :: - :_ state - :_ (weld submission-cards seen-cards) - :+ %give %fact - :+ :~ /local-pages - [%local-pages path] - == - %link-update - !>([%local-pages path [page]~]) -:: +note-note: save a note for a url -:: -++ note-note - |= [=path =url udon=@t] - ^- (quip card _state) - ?< |(=(~ path) =(~ url) =(~ udon)) - :: add note to discussion ours - :: - =/ urls (~(gut by discussions) path *(map ^url discussion)) - =/ =discussion (~(gut by urls) url *discussion) - =/ =note [now.bowl udon] - =. ours.discussion [note ours.discussion] - =. urls (~(put by urls) url discussion) - =. discussions (~(put by discussions) path urls) - :: do generic comment logic - :: - =^ cards state - (read-comment path url [our.bowl note]) - :: send updates to subscribers - :: - :_ state - ^- (list card) - :_ cards - :+ %give %fact - :+ :~ /annotations - [%annotations %$ path] - [%annotations (build-discussion-path:store url)] - [%annotations (build-discussion-path:store path url)] - == - %link-update - !>([%annotations path url [note]~]) -:: +seen-submission: mark url as seen/read -:: -:: if no url specified, all under path are marked as read -:: -++ seen-submission - |= [=path murl=(unit url)] - ^- (quip card _state) - =/ =links (~(gut by by-group) path *links) - :: new: urls we want to, but haven't yet, marked as seen - :: - =/ new=(set url) - %. seen.links - %~ dif in - ^- (set url) - ?^ murl (sy ~[u.murl]) - %- ~(gas in *(set url)) - %+ turn submissions.links - |=(submission url) - ?: =(~ new) [~ state] - =. seen.links (~(uni in seen.links) new) - :_ state(by-group (~(put by by-group) path links)) - [%give %fact ~[/seen] %link-update !>([%observation path new])]~ -:: +hear-submission: record page someone else saved -:: -++ hear-submission - |= [=path =submission] - ^- (quip card _state) - ?< =(~ path) - :: add link to group submissions - :: - =/ =links (~(gut by by-group) path *links) - =^ added submissions.links - ?: ?=(^ (find ~[submission] submissions.links)) - [| submissions.links] - :- & - (submissions:merge:store submissions.links ~[submission]) - =. by-group (~(put by by-group) path links) - :: add submission to global sites - :: - =/ =site (site-from-url:store url.submission) - =. by-site (~(add ja by-site) site [path submission]) - :: send updates to subscribers - :: - :_ state - ?. added ~ - :_ ~ - :+ %give %fact - :+ :~ /submissions - [%submissions path] - == - %link-update - !>([%submissions path [submission]~]) -:: +read-comment: record a comment someone else made -:: -++ read-comment - |= [=path =url =comment] - ^- (quip card _state) - :: add comment to url's discussion - :: - =/ urls (~(gut by discussions) path *(map ^url discussion)) - =/ =discussion (~(gut by urls) url *discussion) - =^ added comments.discussion - ?: ?=(^ (find ~[comment] comments.discussion)) - [| comments.discussion] - :- & - (comments:merge:store comments.discussion ~[comment]) - =. urls (~(put by urls) url discussion) - =. discussions (~(put by discussions) path urls) - :: send updates to subscribers - :: - :_ state - ?. added ~ - :_ ~ - :+ %give %fact - :+ :~ /discussions - [%discussions '' path] - [%discussions (build-discussion-path:store url)] - [%discussions (build-discussion-path:store path url)] - == - %link-update - !>([%discussions path url [comment]~]) -:: -:: reading -:: -++ get-local-pages - |= =path - ^- (map ^path pages) - ?~ path - :: all paths - :: - %- ~(run by by-group) - |=(links ours) - :: specific path - :: - %+ ~(put by *(map ^path pages)) path - ours:(~(gut by by-group) path *links) -:: -++ get-submissions - |= =path - ^- (map ^path submissions) - ?~ path - :: all paths - :: - %- ~(run by by-group) - |=(links submissions) - :: specific path - :: - %+ ~(put by *(map ^path submissions)) path - submissions:(~(gut by by-group) path *links) -:: -++ get-all-unseen - ^- (jug path url) - %- ~(rut by by-group) - |= [=path *] - (get-unseen path) -:: -++ get-unseen - |= =path - ^- (set url) - =/ =links - (~(gut by by-group) path *links) - %- ~(gas in *(set url)) - %+ murn submissions.links - |= submission - ?: (~(has in seen.links) url) ~ - (some url) -:: -++ is-seen - |= =path - ^- ? - =/ [=^path =url] - (break-discussion-path:store path) - %. url - %~ has in - seen:(~(gut by by-group) path *links) -:: -:: -++ get-annotations - |= =path - ^- (per-path-url notes) - =/ args=[=^path =url] - (break-discussion-path:store path) - |^ ?~ path - :: all paths - :: - (~(run by discussions) get-ours) - :: specific path - :: - %+ ~(put by *(per-path-url notes)) path.args - %- get-ours - %+ ~(gut by discussions) path.args - *(map url discussion) - :: - ++ get-ours - |= m=(map url discussion) - ^- (map url notes) - ?: =(~ url.args) - :: all urls - :: - %- ~(run by m) - |=(discussion ours) - :: specific url - :: - %+ ~(put by *(map url notes)) url.args - ours:(~(gut by m) url.args *discussion) + ++ add-graph + |= [=resource =graph:gra] + ^- card + =- [%pass /migrate-link %agent [our.bowl %graph-store] -] + ^- task:agent:gall + :+ %poke %graph-update + !> ^- update:gra + [%0 now.bowl %add-graph resource graph `%graph-validator-link] -- :: -++ get-discussions - |= =path - ^- (per-path-url comments) - =/ args=[=^path =url] - (break-discussion-path:store path) - |^ ?~ path - :: all paths - :: - (~(run by discussions) get-comments) - :: specific path - :: - %+ ~(put by *(per-path-url comments)) path.args - %- get-comments - %+ ~(gut by discussions) path.args - *(map url discussion) - :: - ++ get-comments - |= m=(map url discussion) - ^- (map url comments) - ?: =(~ url.args) - :: all urls - :: - %- ~(run by m) - |=(discussion comments) - :: specific url - :: - %+ ~(put by *(map url comments)) url.args - comments:(~(gut by m) url.args *discussion) - -- +++ on-poke on-poke:def +++ on-peek on-peek:def +++ on-watch on-watch:def +++ on-leave on-leave:def +++ on-agent on-agent:def +++ on-arvo on-arvo:def +++ on-fail on-fail:def -- diff --git a/pkg/arvo/mar/graph/validator/link.hoon b/pkg/arvo/mar/graph/validator/link.hoon index 006feda37..a9c1cbb30 100644 --- a/pkg/arvo/mar/graph/validator/link.hoon +++ b/pkg/arvo/mar/graph/validator/link.hoon @@ -10,13 +10,13 @@ |= p=* =/ ip ;;(indexed-post p) ?+ index.p.ip ~|(index+index.p.ip !!) - :: top-level link post + :: top-level link post; title and url :: [@ ~] - ?> ?=([[%text @] [%url @] [%text @] ~] contents.p.ip) + ?> ?=([[%text @] [%url @] ~] contents.p.ip) ip :: - :: comment on link post + :: comment on link post; comment text :: [@ @ ~] ?> ?=([[%text @] ~] contents.p.ip) From 928e5f7362d2879efaa429382192ac3982f70e6c Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 19 Aug 2020 12:22:20 -0700 Subject: [PATCH 03/43] graph-hooks: initial sketch --- pkg/arvo/app/graph-pull-hook.hoon | 48 +++++++++++++ pkg/arvo/app/graph-push-hook.hoon | 116 ++++++++++++++++++++++++++++++ pkg/arvo/app/graph-store.hoon | 9 +++ pkg/arvo/lib/graph.hoon | 8 ++- 4 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 pkg/arvo/app/graph-pull-hook.hoon create mode 100644 pkg/arvo/app/graph-push-hook.hoon diff --git a/pkg/arvo/app/graph-pull-hook.hoon b/pkg/arvo/app/graph-pull-hook.hoon new file mode 100644 index 000000000..bb3686873 --- /dev/null +++ b/pkg/arvo/app/graph-pull-hook.hoon @@ -0,0 +1,48 @@ +/- *resource +/+ store=graph-store, graph, default-agent, verb, dbug, pull-hook +~% %graph-pull-hook-top ..is ~ +|% ++$ card card:agent:gall +++ config + ^- config:pull-hook + :* %graph-store + update:store + %graph-update + %graph-push-hook + == +-- +:: +%- agent:dbug +^- agent:gall +%- (agent:pull-hook config) +^- (pull-hook:pull-hook config) +|_ =bowl:gall ++* this . + def ~(. (default-agent this %|) bowl) + dep ~(. (default:pull-hook this config) bowl) +:: +++ on-init on-init:def +++ on-save !>(~) +++ on-load on-load:def +++ on-poke on-poke:def +++ on-peek on-peek:def +++ on-arvo on-arvo:def +++ on-fail on-fail:def +++ on-agent on-agent:def +++ on-watch on-watch:def +++ on-leave on-leave:def +++ on-pull-nack + |= [=resource =tang] + ^- (quip card _this) + :_ this + =- [%pass /pull-nack %agent [our.bowl %graph-store] %poke %graph-update -]~ + ^- update:store + !>([%0 now.bowl [%archive-graph resource]) +:: +++ on-pull-kick + |= =resource + ^- (unit path) + =/ maybe-time (peek-log:graph resource) + ?~ maybe-time `/ + `/(scot %da u.maybe-time) +-- diff --git a/pkg/arvo/app/graph-push-hook.hoon b/pkg/arvo/app/graph-push-hook.hoon new file mode 100644 index 000000000..f93fefed7 --- /dev/null +++ b/pkg/arvo/app/graph-push-hook.hoon @@ -0,0 +1,116 @@ +/+ store=graph-store +/+ res=resource +/+ graph +/+ group +/+ default-agent +/+ dbug +/+ push-hook +~% %graph-push-hook-top ..is ~ +|% ++$ card card:agent:gall +++ config + ^- config:push-hook + :* %graph-store + /updates + update:store + %graph-update + %graph-pull-hook + == +:: ++$ agent (push-hook:push-hook config) +-- +:: +%- agent:dbug +^- agent:gall +%- (agent:push-hook config) +^- agent +|_ =bowl:gall ++* this . + def ~(. (default-agent this %|) bowl) + grp ~(. group bowl) + gra ~(. graph bowl) +:: +++ on-init on-init:def +++ on-save !>(~) +++ on-load on-load:def +++ on-poke on-poke:def +++ on-agent on-agent:def +++ on-watch on-watch:def +++ on-leave on-leave:def +++ on-peek on-peek:def +++ on-arvo on-arvo:def +++ on-fail on-fail:def +:: +++ should-proxy-update + |= =vase + ^- ? + =/ =update:store !<(update:store vase) + ?- -.q.update + %add-graph %.y + %remove-graph %.y + %add-nodes %.y + %remove-nodes %.y + %add-signatures %.y + %remove-signatures %.y + %archive-graph %.y + %unarchive-graph %.n + %add-tag %.n + %remove-tag %.n + %keys %.n + %tags %.n + %tag-queries %.n + %run-updates %.y + == +:: +++ resource-for-update + |= =vase + ^- (unit resource:res) + =/ =update:store !<(update:store vase) + ?- -.q.update + %add-graph `resource.q.update + %remove-graph `resource.q.update + %add-nodes `resource.q.update + %remove-nodes `resource.q.update + %add-signatures `resource.uid.q.update + %remove-signatures `resource.uid.q.update + %archive-graph `resource.q.update + %unarchive-graph ~ + %add-tag ~ + %remove-tag ~ + %keys ~ + %tags ~ + %tag-queries ~ + %run-updates `resource.q.update + == +:: +++ initial-watch + |= [=path =resource:res] + ^- vase + ?> (can-join:grp resource src.bowl) + !> ^- update:store + ?~ path + :: new subscribe + :: + =/ [=graph:store mark=(unit mark:store)] + (get-graph:gra resource) + [%0 now.bowl [%add-graph resource graph mark]] + :: resubscribe + :: + =/ =time (slav %da i.path) + =/ =update-log:store (get-update-log-subset:gra resource time) + [%0 now.bowl [%run-updates resource update-log]] +:: +++ take-update + |= =vase + ^- [(list card) agent] + =/ =update:store !<(update:store vase) + ?+ -.q.update [~ this] + %remove-graph + :_ this + [%give %kick ~[resource+(en-path:res resource.q.update)] ~]~ + :: + %archive-graph + :_ this + [%give %kick ~[resource+(en-path:res resource.q.update)] ~]~ + == +-- diff --git a/pkg/arvo/app/graph-store.hoon b/pkg/arvo/app/graph-store.hoon index ab9a6b971..3724b52d9 100644 --- a/pkg/arvo/app/graph-store.hoon +++ b/pkg/arvo/app/graph-store.hoon @@ -511,6 +511,15 @@ %empty [~ ~] %graph ``noun+!>(`graph:store`(subset:orm p.children.u.node start end)) == + :: + [%x %update-log-subset @ @ @ @ ~] + =/ =ship (slav %p i.t.t.path) + =/ =term i.t.t.t.path + =/ start=(unit time) (slaw %da i.t.t.t.t.path) + =/ end=(unit time) (slaw %da i.t.t.t.t.t.path) + =/ update-log=(unit update-log:store) (~(get by update-logs) [ship term]) + ?~ update-log [~ ~] + ``noun+!>((subset:orm-log u.update-log start end)) :: [%x %update-log @ @ ~] =/ =ship (slav %p i.t.t.path) diff --git a/pkg/arvo/lib/graph.hoon b/pkg/arvo/lib/graph.hoon index 395c0554f..6ea0ceba9 100644 --- a/pkg/arvo/lib/graph.hoon +++ b/pkg/arvo/lib/graph.hoon @@ -17,8 +17,14 @@ %+ scry-for marked-graph:store /graph/(scot %p entity.res)/[name.res] :: -++ peek-log +++ peek-update-log |= res=resource ^- (unit time) (scry-for (unit time) /peek-update-log/(scot %p entity.res)/[name.res]) +:: +++ get-update-log-subset + |= [res=resource start=@da] + ^- update-log:store + %+ scry-for update-log:store + /update-log-subset/(scot %p entity.res)/[name.res]/(scot %da start)/'~' -- From b70cae9d7765a42a70c5a7f018b0e310d07a5a43 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 19 Aug 2020 12:26:58 -0700 Subject: [PATCH 04/43] graph-hook: both hooks compile --- pkg/arvo/app/graph-pull-hook.hoon | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/arvo/app/graph-pull-hook.hoon b/pkg/arvo/app/graph-pull-hook.hoon index bb3686873..5971ef948 100644 --- a/pkg/arvo/app/graph-pull-hook.hoon +++ b/pkg/arvo/app/graph-pull-hook.hoon @@ -36,13 +36,13 @@ ^- (quip card _this) :_ this =- [%pass /pull-nack %agent [our.bowl %graph-store] %poke %graph-update -]~ - ^- update:store - !>([%0 now.bowl [%archive-graph resource]) + !> ^- update:store + [%0 now.bowl [%archive-graph resource]] :: ++ on-pull-kick |= =resource ^- (unit path) - =/ maybe-time (peek-log:graph resource) + =/ maybe-time (peek-update-log:graph resource) ?~ maybe-time `/ `/(scot %da u.maybe-time) -- From a4e21da3f0d3020c1e1e04b2d2434b471e692067 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 19 Aug 2020 12:31:47 -0700 Subject: [PATCH 05/43] hood: starts %graph-pull-hook and %graph-push-hook --- pkg/arvo/app/hood.hoon | 3 ++- pkg/arvo/lib/hood/drum.hoon | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/arvo/app/hood.hoon b/pkg/arvo/app/hood.hoon index 1bc70ed80..a816843c0 100644 --- a/pkg/arvo/app/hood.hoon +++ b/pkg/arvo/app/hood.hoon @@ -2,7 +2,7 @@ /+ drum=hood-drum, helm=hood-helm, kiln=hood-kiln |% +$ state - $: %9 + $: %10 drum=state:drum helm=state:helm kiln=state:kiln @@ -12,6 +12,7 @@ [ver=?(%1 %2 %3 %4 %5 %6) lac=(map @tas fin-any-state)] [%7 drum=state:drum helm=state:helm kiln=state:kiln] [%8 drum=state:drum helm=state:helm kiln=state:kiln] + [%9 drum=state:drum helm=state:helm kiln=state:kiln] == +$ any-state-tuple $: drum=any-state:drum diff --git a/pkg/arvo/lib/hood/drum.hoon b/pkg/arvo/lib/hood/drum.hoon index e7b91cfbe..a41c917a7 100644 --- a/pkg/arvo/lib/hood/drum.hoon +++ b/pkg/arvo/lib/hood/drum.hoon @@ -105,6 +105,8 @@ %file-server %glob %graph-store + %graph-pull-hook + %graph-push-hook == :: ++ deft-fish :: default connects @@ -207,7 +209,7 @@ == :: ++ on-load - |= [hood-version=?(%1 %2 %3 %4 %5 %6 %7 %8 %9) old=any-state] + |= [hood-version=?(%1 %2 %3 %4 %5 %6 %7 %8 %9 %10) old=any-state] =< se-abet =< se-view =. sat old =. dev (~(gut by bin) ost *source) @@ -236,6 +238,9 @@ (se-born | %home %group-pull-hook) =? ..on-load (lte hood-version %9) (se-born | %home %graph-store) + =? ..on-load (lte hood-version %10) + => (se-born | %home %graph-push-hook) + (se-born | %home %graph-pull-hook) ..on-load :: ++ reap-phat :: ack connect From 291ec5526bf2d62510816f4453e75810cb4c83cf Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 19 Aug 2020 16:21:42 -0700 Subject: [PATCH 06/43] link-hooks: deactivated and deleted state --- pkg/arvo/app/link-listen-hook.hoon | 650 ++--------------------------- pkg/arvo/app/link-proxy-hook.hoon | 342 +-------------- 2 files changed, 47 insertions(+), 945 deletions(-) diff --git a/pkg/arvo/app/link-listen-hook.hoon b/pkg/arvo/app/link-listen-hook.hoon index 9fae8d98b..feb5ffb1e 100644 --- a/pkg/arvo/app/link-listen-hook.hoon +++ b/pkg/arvo/app/link-listen-hook.hoon @@ -1,644 +1,42 @@ -:: link-listen-hook: get your friends' bookmarks +:: link-listen-hook: no longer in use :: -:: keeps track of a listening=(set app-path). users can manually add to and -:: remove from this set. -:: -:: for all ships in groups associated with those resources, we subscribe to -:: their link's local-pages and annotations at the resource path (through -:: link-proxy-hook), and forward all entries into our link-store as -:: submissions and comments. -:: -:: if a subscription to a target fails, we assume it's because their -:: metadata+groups definition hasn't been updated to include us yet. -:: we retry with exponential backoff, maxing out at one hour timeouts. -:: to expede this process, we prod other potential listeners when we add -:: them to our metadata+groups definition. -:: -:: -/- listen-hook=link-listen-hook, *metadata-store, *group, *link -/+ mdl=metadata, default-agent, verb, dbug, group-store, grpl=group, resource, store=link-store +/+ default-agent, verb, dbug :: ~% %link-listen-hook-top ..is ~ |% +$ versioned-state - $% [%0 state-0] - [%1 state-1] - [%2 state-2] - [%3 state-3] + $% [%0 *] + [%1 *] + [%2 *] + [%3 *] + [%4 ~] == -+$ state-3 state-1 -+$ state-2 state-1 -+$ state-1 - $: listening=(set app-path) - state-0 - == -+$ state-0 - $: retry-timers=(map target @dr) - :: reasoning: the resources we're subscribed to, - :: and the groups that cause that. - :: - :: we don't strictly need to track this in state, but doing so heavily - :: simplifies logic and reduces the amount of big scries we do. - :: this also gives us the option to check & restore subscriptions, - :: should we ever need that. - :: - reasoning=(jug [ship app-path] group-path) - == -:: -+$ what-target ?(%local-pages %annotations) -+$ target - $: what=what-target - who=ship - where=path - == -++ wire-to-target - |= =wire - ^- target - ?> ?=([what-target @ ^] wire) - [i.wire (slav %p i.t.wire) t.t.wire] -++ target-to-wire - |= target - ^- wire - [what (scot %p who) where] -:: +$ card card:agent:gall -- :: -=| [%3 state-3] +=| [%4 ~] =* state - :: %- agent:dbug %+ verb | ^- agent:gall -=< - |_ =bowl:gall - +* this . - do ~(. +> bowl) - def ~(. (default-agent this %|) bowl) - :: - ++ on-init - ^- (quip card _this) - :_ this - ~[watch-metadata:do watch-groups:do] - :: - ++ on-save !>(state) - ++ on-load - |= =vase - ^- (quip card _this) - =/ old=versioned-state - !<(versioned-state vase) - =| cards=(list card) - |- - =* upgrade-loop $ - ?- -.old - %3 [cards this(state old)] - :: - %2 - :_ this(state [%3 +.old]) - %+ welp cards - :~ [%pass /groups %agent [our.bowl %group-store] %leave ~] - watch-groups:do - == - :: - %1 - :: the upgrade from 0 left out local-only collections. - :: here, we pull those back in. - :: - =. listening.old - (~(run in ~(key by reasoning.old)) tail) - =/ resources=(list [=group-path =app-path]) - %~ tap in - %. %link - %~ get ju - .^ (jug app-name [group-path app-path]) - %gy - (scot %p our.bowl) - %metadata-store - (scot %da now.bowl) - /app-indices - == - |- - ?~ resources - upgrade-loop(old [%2 +.old]) - =, i.resources - =/ members=(set ship) - (members-from-path:grp:do group-path) - :: if we're the only group member, this got incorrectly ignored - :: during 0's upgrade logic. watch it now. - :: - ?. &(=(1 ~(wyt in members)) (~(has in members) our.bowl)) - $(resources t.resources) - =^ more-cards state - (handle-listen-action:do %watch app-path) - $(resources t.resources, cards (weld more-cards cards)) - :: - %0 - =/ listening=(set app-path) - (~(run in ~(key by reasoning.old)) tail) - $(old [%1 listening +.old]) - == - :: - ++ on-agent - |= [=wire =sign:agent:gall] - ^- (quip card _this) - =^ cards state - ?+ wire ~|([dap.bowl %weird-agent-wire wire] !!) - [%metadata ~] - (take-metadata-sign:do sign) - :: - [%groups ~] - (take-groups-sign:do sign) - :: - [%links ?(%local-pages %annotations) @ ^] - (take-link-sign:do (wire-to-target t.wire) sign) - :: - [%forward ^] - (take-forward-sign:do t.wire sign) - :: - [%prod *] - ?> ?=(%poke-ack -.sign) - ?~ p.sign [~ state] - %- (slog leaf+"prod failed" u.p.sign) - [~ state] - == - [cards this] - :: - ++ on-poke - |= [=mark =vase] - ?+ mark (on-poke:def mark vase) - %link-listen-poke - =/ =path !<(path vase) - :_ this - %+ weld - (take-retry:do %local-pages src.bowl path) - (take-retry:do %annotations src.bowl path) - :: - %link-listen-action - ?> (team:title [our src]:bowl) - =^ cards state - ~| p.vase - (handle-listen-action:do !<(action:listen-hook vase)) - [cards this] - == - :: - ++ on-arvo - |= [=wire =sign-arvo] - ^- (quip card _this) - ?+ sign-arvo (on-arvo:def wire sign-arvo) - [%g %done *] - ?~ error.sign-arvo [~ this] - =/ =tank leaf+"{(trip dap.bowl)}'s message went wrong!" - %- (slog tank tang.u.error.sign-arvo) - [~ this] - :: - [%b %wake *] - ?> ?=([%retry @ @ ^] wire) - ?^ error.sign-arvo - =/ =tank leaf+"wake on {(spud wire)} went wrong!" - %- (slog tank u.error.sign-arvo) - [~ this] - :_ this - (take-retry:do (wire-to-target t.wire)) - == - :: - ++ on-peek - |= =path - ^- (unit (unit cage)) - ?+ path ~ - [%x %listening ~] ``noun+!>(listening) - [%x %listening ^] ``noun+!>((~(has in listening) t.t.path)) - == - :: - ++ on-watch - |= =path - ^- (quip card _this) - ?. ?=([%listening ~] path) (on-watch:def path) - ?> (team:title [our src]:bowl) - :_ this - [%give %fact ~ %link-listen-update !>([%listening listening])]~ - :: - ++ on-leave on-leave:def - ++ on-fail on-fail:def - -- -:: -:: |_ =bowl:gall -+* md ~(. mdl bowl) -++ grp ~(. grpl bowl) ++* this . + def ~(. (default-agent this %|) bowl) :: -:: user actions & updates +++ on-init [~ this] +++ on-save !>(state) +++ on-load + |= =vase + ^- (quip card _this) + :_ this + [%pass /groups %agent [our.bowl %group-store] %leave ~]~ :: -++ handle-listen-action - |= =action:listen-hook - ^- (quip card _state) - ::NOTE no-opping where appropriate happens further down the call stack. - :: we *could* no-op here, as %watch when we're already listening should - :: result in no-ops all the way down, but walking through everything - :: makes this a nice "resurrect if broken unexpectedly" option. - :: - =* app-path path.action - =^ cards listening - ^- (quip card _listening) - =/ had=? (~(has in listening) app-path) - ?- -.action - %watch - :_ (~(put in listening) app-path) - ?:(had ~ [(send-update action)]~) - :: - %leave - :_ (~(del in listening) app-path) - ?.(had ~ [(send-update action)]~) - == - =/ groups=(list group-path) - (groups-from-resource:md %link app-path) - |- - ?~ groups [cards state] - =^ more-cards state - ?- -.action - %watch (listen-to-group app-path i.groups) - %leave (leave-from-group app-path i.groups) - == - $(cards (weld cards more-cards), groups t.groups) -:: -++ send-update - |= =update:listen-hook - ^- card - [%give %fact ~[/listening] %link-listen-update !>(update)] -:: -:: metadata subscription -:: -++ watch-metadata - ^- card - [%pass /metadata %agent [our.bowl %metadata-store] %watch /app-name/link] -:: -++ take-metadata-sign - |= =sign:agent:gall - ^- (quip card _state) - ?- -.sign - %poke-ack ~|([dap.bowl %unexpected-poke-ack /metadata] !!) - %kick [[watch-metadata]~ state] - :: - %watch-ack - ?~ p.sign [~ state] - =/ =tank - :- %leaf - "{(trip dap.bowl)} failed subscribe to metadata store. very wrong!" - %- (slog tank u.p.sign) - [~ state] - :: - %fact - =* mark p.cage.sign - =* vase q.cage.sign - ?. ?=(%metadata-update mark) - ~| [dap.bowl %unexpected-mark mark] - !! - %- handle-metadata-update - !<(metadata-update vase) - == -:: -++ handle-metadata-update - |= upd=metadata-update - ^- (quip card _state) - ?+ -.upd [~ state] - %add - ?> =(%link app-name.resource.upd) - :: auto-listen to collections in unmanaged groups only - :: - =/ rid=resource - (de-path:resource group-path.upd) - =/ =group - (need (scry-group:grp rid)) - ?. hidden.group - [~ state] - =, resource.upd - =^ update listening - ^- (quip card _listening) - ?: (~(has in listening) app-path) - [~ listening] - :- [(send-update %watch app-path)]~ - (~(put in listening) app-path) - =^ cards state - (listen-to-group app-path group-path.upd) - [(weld update cards) state] - :: - %remove - ?> =(%link app-name.resource.upd) - =? listening - ?=(~ (groups-from-resource:md %link app-path.resource.upd)) - (~(del in listening) app-path.resource.upd) - (leave-from-group app-path.resource.upd group-path.upd) - == -:: -:: groups subscriptions -:: -++ watch-groups - ^- card - [%pass /groups %agent [our.bowl %group-store] %watch /groups] -:: -++ take-groups-sign - |= =sign:agent:gall - ^- (quip card _state) - ?- -.sign - %poke-ack ~|([dap.bowl %unexpected-poke-ack /groups] !!) - %kick [[watch-groups]~ state] - :: - %watch-ack - ?~ p.sign [~ state] - =/ =tank - :- %leaf - "{(trip dap.bowl)} failed subscribe to groups. very wrong!" - %- (slog tank u.p.sign) - [~ state] - :: - %fact - =* mark p.cage.sign - =* vase q.cage.sign - ?+ mark ~|([dap.bowl %unexpected-mark mark] !!) - %group-initial [~ state] ::NOTE initial handled using metadata - %group-update (handle-group-update !<(update:group-store vase)) - == - == -:: -++ handle-group-update - |= upd=update:group-store - ^- (quip card _state) - ?. ?=(?(%add-members %initial-group %remove-members) -.upd) - [~ state] - =/ =path - (en-path:resource resource.upd) - =/ socs=(list app-path) - (app-paths-from-group:md %link path) - =/ whos=(list ship) - ?- -.upd - %add-members ~(tap in ships.upd) - %remove-members ~(tap in ships.upd) - %initial-group ~(tap in members.group.upd) - == - =| cards=(list card) - |- - =* loop-socs $ - ?~ socs [cards state] - ?. (~(has in listening) i.socs) - loop-socs(socs t.socs) - |- - =* loop-whos $ - ?~ whos loop-socs(socs t.socs) - =^ caz state - ?. ?=(%remove-members -.upd) - (listen-to-peer i.socs path i.whos) - ?: =(our.bowl i.whos) - (handle-listen-action %leave i.socs) - (leave-from-peer i.socs path i.whos) - loop-whos(whos t.whos, cards (weld cards caz)) -:: -:: link subscriptions -:: -++ listen-to-group - |= [=app-path =group-path] - ^- (quip card _state) - =/ peers=(list ship) - ~| group-path - %~ tap in - (members-from-path:grp group-path) - =| cards=(list card) - |- - ?~ peers [cards state] - =^ caz state - (listen-to-peer app-path group-path i.peers) - $(peers t.peers, cards (weld cards caz)) -:: -++ leave-from-group - |= [=app-path =group-path] - ^- (quip card _state) - =/ peers=(list ship) - %~ tap in - (members-from-path:grp group-path) - =| cards=(list card) - |- - ?~ peers [cards state] - =^ caz state - (leave-from-peer app-path group-path i.peers) - $(peers t.peers, cards (weld cards caz)) -:: -++ listen-to-peer - |= [=app-path =group-path who=ship] - ^- (quip card _state) - ?: =(our.bowl who) - [~ state] - :_ =- state(reasoning -) - (~(put ju reasoning) [who app-path] group-path) - :- (prod-other-listener who app-path) - ?^ (~(get ju reasoning) [who app-path]) - ~ - (start-link-subscriptions who app-path) -:: -++ leave-from-peer - |= [=app-path =group-path who=ship] - ^- (quip card _state) - ?: =(our.bowl who) - [~ state] - =. reasoning (~(del ju reasoning) [who app-path] group-path) - ::NOTE leaving is always safe, so we just do it unconditionally - (end-link-subscriptions who app-path) -:: -++ start-link-subscriptions - |= [=ship =app-path] - ^- (list card) - :~ (start-link-subscription %local-pages ship app-path) - (start-link-subscription %annotations ship app-path) - == -:: -++ start-link-subscription - |= =target - ^- card - :* %pass - [%links (target-to-wire target)] - %agent - [who.target %link-proxy-hook] - %watch - ?- what.target - %local-pages [what where]:target - %annotations [what %$ where]:target - == - == -:: -++ end-link-subscriptions - |= [who=ship where=path] - ^- (quip card _state) - =. retry-timers (~(del by retry-timers) [%local-pages who where]) - =. retry-timers (~(del by retry-timers) [%annotations who where]) - :_ state - |^ ~[(end %local-pages) (end %annotations)] - :: - ++ end - |= what=what-target - :* %pass - [%links (target-to-wire what who where)] - %agent - [who %link-proxy-hook] - %leave - ~ - == - -- -:: -++ prod-other-listener - |= [who=ship where=path] - ^- card - :* %pass - [%prod (scot %p who) where] - %agent - [who %link-listen-hook] - %poke - %link-listen-poke - !>(where) - == -:: -++ take-link-sign - |= [=target =sign:agent:gall] - ^- (quip card _state) - ?- -.sign - %poke-ack ~|([dap.bowl %unexpected-poke-ack /links target] !!) - %kick [[(start-link-subscription target)]~ state] - :: - %watch-ack - ?~ p.sign - =. retry-timers (~(del by retry-timers) target) - [~ state] - :: our subscription request got rejected, - :: most likely because our group definition is out of sync with theirs. - :: set timer for retry. - :: - (start-retry target) - :: - %fact - =* mark p.cage.sign - =* vase q.cage.sign - ?+ mark ~|([dap.bowl %unexpected-mark mark] !!) - %link-initial - %- handle-link-initial - [who.target where.target !<(initial:store vase)] - :: - %link-update - %- handle-link-update - [who.target where.target !<(update:store vase)] - == - == -:: -++ start-retry - |= =target - ^- (quip card _state) - =/ timer=@dr - %+ min ~h1 - %+ mul 2 - (~(gut by retry-timers) target ~s15) - =. retry-timers - (~(put by retry-timers) target timer) - :_ state - :_ ~ - :* %pass - [%retry (target-to-wire target)] - [%arvo %b %wait (add now.bowl timer)] - == -:: -++ take-retry - |= =target - ^- (list card) - :: relevant: whether :who is still associated with resource :where - :: - =; relevant=? - ?. relevant ~ - [(start-link-subscription target)]~ - ?. (~(has in listening) where.target) - | - ?: %- ~(has by wex.bowl) - [[%links (target-to-wire target)] who.target %link-proxy-hook] - | - %+ lien (groups-from-resource:md %link where.target) - |= =group-path - ^- ? - %. who.target - ~(has in (members-from-path:grp group-path)) - -:: -++ do-link-action - |= [=wire =action:store] - ^- card - :* %pass - wire - %agent - [our.bowl %link-store] - %poke - %link-action - !>(action) - == -:: -++ handle-link-initial - |= [who=ship where=path =initial:store] - ^- (quip card _state) - ?> =(src.bowl who) - ?+ -.initial ~|([dap.bowl %unexpected-initial -.initial] !!) - %local-pages - =/ =pages (~(got by pages.initial) where) - (handle-link-update who where [%local-pages where pages]) - :: - %annotations - =/ urls=(list [=url =notes]) - ~(tap by (~(got by notes.initial) where)) - =| cards=(list card) - |- ^- (quip card _state) - ?~ urls [cards state] - =^ caz state - ^- (quip card _state) - =, i.urls - (handle-link-update who where [%annotations where url notes]) - $(urls t.urls, cards (weld cards caz)) - == -:: -++ handle-link-update - |= [who=ship where=path =update:store] - ^- (quip card _state) - ?> =(src.bowl who) - :_ state - ?+ -.update ~|([dap.bowl %unexpected-update -.update] !!) - %local-pages - %+ turn pages.update - |= =page - %+ do-link-action - [%forward %local-page (scot %p who) where] - [%hear where who page] - :: - %annotations - %+ turn notes.update - |= =note - ^- card - %+ do-link-action - `wire`[%forward %annotation (scot %p who) where] - `action:store`[%read where url.update `comment`[who note]] - == -:: -++ take-forward-sign - |= [=wire =sign:agent:gall] - ^- (quip card _state) - ~| [%unexpected-sign on=[%forward wire] -.sign] - ?> ?=(%poke-ack -.sign) - ?~ p.sign [~ state] - =/ =tank - :- %leaf - ;: weld - (trip dap.bowl) - " failed to save submission from " - (spud wire) - == - %- (slog tank u.p.sign) - [~ state] -:: -++ scry-for - |* [=mold =app-name =path] - .^ mold - %gx - (scot %p our.bowl) - app-name - (scot %da now.bowl) - (snoc `^path`path %noun) - == +++ on-agent on-agent:def +++ on-poke on-poke:def +++ on-arvo on-arvo:def +++ on-peek on-peek:def +++ on-watch on-watch:def +++ on-leave on-leave:def +++ on-fail on-fail:def -- diff --git a/pkg/arvo/app/link-proxy-hook.hoon b/pkg/arvo/app/link-proxy-hook.hoon index 98f61f6f8..ffa822ee6 100644 --- a/pkg/arvo/app/link-proxy-hook.hoon +++ b/pkg/arvo/app/link-proxy-hook.hoon @@ -1,337 +1,41 @@ -:: link-proxy-hook: make local pages available to foreign ships +:: link-proxy-hook: no longer in use :: -:: this is a "proxy" style hook, relaying foreign subscriptions into local -:: stores if permission conditions are met. -:: the patterns herein should one day be generalized into a proxy-hook lib. -:: -:: this uses metadata-store to discover resources and their associated -:: groups. it sets the permission condition to be that a ship must be in a -:: group associated with the resource it's subscribing to. -:: we check this on-watch, but also subscribe to metadata & groups so that -:: we can kick subscriptions if needed (eg ship removed from group). -:: -:: we deduplicate incoming subscriptions on the same path, ensuring we have -:: exactly one local subscription per unique incoming subscription path. -:: this comes at the cost of assuming that the store's initial response is -:: whatever's returned by the scry at that path, but perhaps that should -:: become part of the stores standard anyway. -:: -:: when adding support for new paths, the only things you'll likely want -:: to touch are +permitted, +initial-response, & +kick-proxies. -:: -/- *link, *metadata-store, *group -/+ metadata, default-agent, verb, dbug, group-store, grpl=group, - resource, store=link-store +/+ default-agent, verb, dbug ~% %link-proxy-hook-top ..is ~ |% -+$ state-0 - $: %0 - ::TODO we use this to detect "first sub started" and "last sub left", - :: but can't we use [wex sup]:bowl for that? - active=(map path (set ship)) - == -+$ state-1 - $: %1 - active=(map path (set ship)) - == -:: +$ versioned-state - $% state-0 - state-1 + $% [%0 *] + [%1 *] + [%2 ~] == :: +$ card card:agent:gall -- :: -=| state-1 +=| [%2 ~] =* state - :: %- agent:dbug %+ verb | ^- agent:gall -=< - |_ =bowl:gall - +* this . - do ~(. +> bowl) - def ~(. (default-agent this %&) bowl) - :: - ++ on-init - ^- (quip card _this) - :_ this - ~[watch-groups:do watch-metadata:do] - :: - ++ on-save !>(state) - ++ on-load - |= old-vase=vase - ^- (quip card _this) - =/ old - !<(versioned-state old-vase) - ?- -.old - %1 [~ this(state old)] - :: - %0 - :_ this(state [%1 +.old]) - :~ [%pass /groups %agent [our.bowl %group-store] %leave ~] - watch-groups:do - == - == - - :: - ++ on-watch - |= =path - ^- (quip card _this) - :: the local ship should just use link-store directly - ::TODO do we want to allow this anyway, to avoid client-side target checks? - :: - ?< (team:title [our src]:bowl) - ?> (permitted:do src.bowl path) - =^ cards state - (start-proxy:do src.bowl path) - [cards this] - :: - ++ on-leave - |= =path - ^- (quip card _this) - =^ cards state - (stop-proxy:do src.bowl path) - [cards this] - :: - ++ on-agent - |= [=wire =sign:agent:gall] - ^- (quip card _this) - ?: ?=([%groups ~] wire) - =^ cards state - (take-groups-sign:do sign) - [cards this] - ?: ?=([%proxy ^] wire) - =^ cards state - (handle-proxy-sign t.wire sign) - [cards this] - ~| [dap.bowl %weird-wire wire] - !! - :: - ++ on-poke on-poke:def - ++ on-peek on-peek:def - ++ on-arvo on-arvo:def - ++ on-fail on-fail:def - -- -:: |_ =bowl:gall -+* md ~(. metadata bowl) - grp ~(. grpl bowl) ++* this . + def ~(. (default-agent this %&) bowl) :: -:: permissions +++ on-init on-init:def +++ on-save !>(state) +++ on-load + |= old-vase=vase + ^- (quip card _this) + :_ this + [%pass /groups %agent [our.bowl %group-store] %leave ~]~ :: -++ permitted - |= [who=ship =path] - ^- ? - :: we only expose /local-pages and /annotations, - :: to ships in the groups associated with the resource. - :: (no url-specific annotations subscriptions, either.) - :: - =/ target=(unit ^path) - ?: ?=([%local-pages ^] path) - `t.path - ?: ?=([%annotations ~ ^] path) - `t.t.path - ~ - ?~ target | - %+ lien (groups-from-resource:md %link u.target) - |= =group-path - ^- ? - (~(has in (members-from-path:grp group-path)) who) -:: -++ kick-revoked-permissions - |= [=path who=(list ship)] - ^- (list card) - %+ murn who - |= =ship - ^- (unit card) - :: no need to remove to ourselves - :: - ?: =(our.bowl ship) ~ - ?: (permitted ship path) ~ - `(kick-proxies ship path) -:: -:: metadata subscription -:: -++ watch-metadata - ^- card - [%pass /metadata %agent [our.bowl %metadata-store] %watch /app-name/link] -:: -++ take-metadata-sign - |= =sign:agent:gall - ^- (quip card _state) - ?- -.sign - %poke-ack ~|([dap.bowl %unexpected-poke-ack /metadata] !!) - %kick [[watch-metadata]~ state] - :: - %watch-ack - ?~ p.sign [~ state] - =/ =tank - :- %leaf - "{(trip dap.bowl)} failed subscribe to metadata store. very wrong!" - %- (slog tank u.p.sign) - [~ state] - :: - %fact - =* mark p.cage.sign - =* vase q.cage.sign - ?. ?=(%metadata-update mark) - ~| [dap.bowl %unexpected-mark mark] - !! - %- handle-metadata-update - !<(metadata-update vase) - == -:: -++ handle-metadata-update - |= upd=metadata-update - ^- (quip card _state) - :_ state - ?. ?=(%remove -.upd) ~ - ?> =(%link app-name.resource.upd) - :: if a group is no longer associated with a resource, - :: we need to re-check permissions for everyone in that group. - :: - %+ kick-revoked-permissions - app-path.resource.upd - %~ tap in - (members-from-path:grp group-path.upd) -:: -:: groups subscription -::TODO largely copied from link-listen-hook. maybe make a store-listener lib? -:: -++ watch-groups - ^- card - [%pass /groups %agent [our.bowl %group-store] %watch /groups] -:: -++ take-groups-sign - |= =sign:agent:gall - ^- (quip card _state) - ?- -.sign - %poke-ack ~|([dap.bowl %unexpected-poke-ack /groups] !!) - %kick [[watch-groups]~ state] - :: - %watch-ack - ?~ p.sign [~ state] - =/ =tank - :- %leaf - "{(trip dap.bowl)} failed subscribe to group store. very wrong!" - %- (slog tank u.p.sign) - [~ state] - :: - %fact - =* mark p.cage.sign - =* vase q.cage.sign - ?+ mark ~|([dap.bowl %unexpected-mark mark] !!) - %group-initial [~ state] - %group-update (handle-group-update !<(update:group-store vase)) - == - == -:: -++ handle-group-update - |= upd=update:group-store - ^- (quip card _state) - :_ state - ?. ?=(%remove-members -.upd) ~ - :: if someone was removed from a group, find all link resources associated - :: with that group, then kick their subscriptions if they're no longer - :: - %- zing - %+ turn (app-paths-from-group:md %link (en-path:resource resource.upd)) - |= =app-path - ^- (list card) - %+ kick-revoked-permissions - app-path - ~(tap in ships.upd) -:: -:: proxy subscriptions -:: -++ kick-proxies - |= [who=ship =path] - ^- card - =- [%give %kick - `who] - :~ [%local-pages path] - [%annotations %$ path] - == -:: -++ handle-proxy-sign - |= [=wire =sign:agent:gall] - ^- (quip card _state) - ?- -.sign - %poke-ack ~|([dap.bowl %unexpected-poke-ack wire] !!) - %fact [[%give %fact ~[wire] cage.sign]~ state] - %kick [[(proxy-pass-link-store wire %watch wire)]~ state] - :: - %watch-ack - ?~ p.sign [~ state] - =/ =tank - :- %leaf - "{(trip dap.bowl)} failed subscribe to link-store. very wrong!" - %- (slog tank u.p.sign) - [~ state] - == -:: -++ proxy-pass-link-store - |= [=path =task:agent:gall] - ^- card - :* %pass - [%proxy path] - %agent - [our.bowl %link-store] - task - == -:: -++ initial-response - |= =path - ^- card - =; =initial:store - [%give %fact ~ %link-initial !>(initial)] - ?+ path !! - [%local-pages ^] - [%local-pages (scry-for (map ^path pages) %link-store path)] - :: - [%annotations %$ ^] - [%annotations (scry-for (per-path-url notes) %link-store path)] - == -:: -++ start-proxy - |= [who=ship =path] - ^- (quip card _state) - :_ state(active (~(put ju active) path who)) - :_ ~ - :: if we already have a local subscription open, - :: - ?. =(~ (~(get ju active) path)) - :: gather the initial response ourselves, and send that. - :: - (initial-response path) - :: else, open a local subscription, - :: sending outward its initial response when we hear it. - :: - (proxy-pass-link-store path %watch path) -:: -++ stop-proxy - |= [who=ship =path] - ^- (quip card _state) - =. active (~(del ju active) path who) - :_ state - :: if there are still subscriptions remaining, do nothing. - :: - ?. =(~ (~(get ju active) path)) ~ - :: else, close the local subscription. - :: - [(proxy-pass-link-store path %leave ~)]~ -:: -:: helpers -:: -++ scry-for - |* [=mold =app-name =path] - .^ mold - %gx - (scot %p our.bowl) - app-name - (scot %da now.bowl) - (snoc `^path`path %noun) - == +++ on-watch on-watch:def +++ on-leave on-leave:def +++ on-agent on-agent:def +++ on-poke on-poke:def +++ on-peek on-peek:def +++ on-arvo on-arvo:def +++ on-fail on-fail:def -- + From 5838b017f8f5cd2f72b7367c3d3c990a640c0265 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 19 Aug 2020 16:26:21 -0700 Subject: [PATCH 07/43] link: deactivated view --- pkg/arvo/app/link-view.hoon | 632 ++---------------------------------- 1 file changed, 23 insertions(+), 609 deletions(-) diff --git a/pkg/arvo/app/link-view.hoon b/pkg/arvo/app/link-view.hoon index 4e5fe6de7..9ddb2b881 100644 --- a/pkg/arvo/app/link-view.hoon +++ b/pkg/arvo/app/link-view.hoon @@ -1,626 +1,40 @@ -:: link-view: frontend endpoints -:: -:: endpoints, mapping onto link-store's paths. p is for page as in pagination. -:: only the /0/submissions endpoint provides updates. -:: as with link-store, urls are expected to use +wood encoding. -:: -:: /json/0/submissions initial + updates for all -:: /json/[p]/submissions/[collection] page for one collection -:: /json/[p]/discussions/[wood-url]/[collection] page for url in collection -:: /json/[n]/submission/[wood-url]/[collection] nth matching submission -:: /json/seen mark-as-read updates -:: -/- *link, view=link-view -/- *invite-store, group-store -/- listen-hook=link-listen-hook -/- group-hook, permission-hook, permission-group-hook -/- metadata-hook, contact-view -/- pull-hook, *group -/+ store=link-store, metadata, *server, default-agent, verb, dbug, grpl=group -/+ group-store, resource +:: link-view: no longer in use +/+ default-agent, verb, dbug ~% %link-view-top ..is ~ -:: -:: |% +$ versioned-state - $% state-0 - state-1 - == -+$ state-0 - $: %0 - ~ - == -:: -+$ state-1 - $: %1 - ~ + $% [%0 ~] + [%1 ~] + [%2 ~] == :: +$ card card:agent:gall -- :: -=| state-1 +=| [%2 ~] =* state - :: %+ verb | %- agent:dbug ^- agent:gall -=< - |_ =bowl:gall - +* this . - do ~(. +> bowl) - def ~(. (default-agent this %|) bowl) - :: - ++ on-init - ^- (quip card _this) - :_ this - :~ [%pass /submissions %agent [our.bowl %link-store] %watch /submissions] - [%pass /discussions %agent [our.bowl %link-store] %watch /discussions] - [%pass /seen %agent [our.bowl %link-store] %watch /seen] - :: - =+ [%invite-action !>([%create /link])] - [%pass /invitatory/create %agent [our.bowl %invite-store] %poke -] - :: - =+ /invitatory/link - [%pass - %agent [our.bowl %invite-store] %watch -] - :* %pass /srv %agent [our.bowl %file-server] - %poke %file-server-action - !>([%serve-dir /'~link' /app/landscape %.n]) - == - == - :: - ++ on-save !>(state) - ++ on-load - |= old-vase=vase - ^- (quip card _this) - =/ old !<(versioned-state old-vase) - ?- -.old - %1 [~ this] - %0 - :_ this(state [%1 ~]) - :- [%pass /connect %arvo %e %disconnect [~ /'~link']] - :~ :* %pass /srv %agent [our.bowl %file-server] - %poke %file-server-action - !>([%serve-dir /'~link' /app/landscape %.n]) - == == - == - :: - ++ on-poke - |= [=mark =vase] - ^- (quip card _this) - ?> (team:title our.bowl src.bowl) - :_ this - ?+ mark (on-poke:def mark vase) - %link-action - [(handle-action:do !<(action:store vase)) ~] - :: - %link-view-action - (handle-view-action:do !<(action:view vase)) - == - :: - ++ on-watch - |= =path - ^- (quip card _this) - ?: ?=([%json %seen ~] path) - [~ this] - ?: ?=([%tile ~] path) - :_ this - ~[give-tile-data:do] - ?. ?=([%json @ @ *] path) - (on-watch:def path) - =/ p=@ud (slav %ud i.t.path) - ?+ t.t.path (on-watch:def path) - [%submissions ~] - :_ this - (give-initial-submissions:do p ~) - :: - [%submissions ^] - :_ this - (give-initial-submissions:do p t.t.t.path) - :: - [%submission @ ^] - :_ this - (give-specific-submission:do p (break-discussion-path:store t.t.t.path)) - :: - [%discussions @ ^] - :_ this - (give-initial-discussions:do p (break-discussion-path:store t.t.t.path)) - == - :: - ++ on-agent - |= [=wire =sign:agent:gall] - ^- (quip card _this) - ?+ -.sign (on-agent:def wire sign) - %poke-ack - ?. ?=([%join-group @ @ @ @ ~] wire) - (on-agent:def wire sign) - ?^ p.sign - (on-agent:def wire sign) - =/ rid=resource - (de-path:resource t.t.wire) - =/ host=ship - (slav %p i.t.wire) - :_ this - (joined-group:do host rid) - :: - %kick - :_ this - =/ app=term - ?: ?=([%invites *] wire) - %invite-store - %link-store - [%pass wire %agent [our.bowl app] %watch wire]~ - :: - %fact - =* mark p.cage.sign - =* vase q.cage.sign - ?+ mark (on-agent:def wire sign) - %invite-update [(handle-invite-update:do !<(invite-update vase)) this] - %link-initial [~ this] - :: - %link-update - :_ this - :- (send-update:do !<(update:store vase)) - ?: =(/discussions wire) ~ - ~[give-tile-data:do] - == - == - :: - ++ on-arvo - |= [=wire =sign-arvo] - ^- (quip card _this) - ?. ?=([%e %bound *] sign-arvo) - (on-arvo:def wire sign-arvo) - ~? !accepted.sign-arvo - [dap.bowl "bind rejected!" binding.sign-arvo] - [~ this] - :: - ++ on-peek on-peek:def - ++ on-leave on-leave:def - ++ on-fail on-fail:def - -- -:: -~% %link-view-logic ..card ~ |_ =bowl:gall -+* md ~(. metadata bowl) - grp ~(. grpl bowl) ++* this . + def ~(. (default-agent this %|) bowl) :: -++ page-size 25 -++ get-paginated - |* [page=(unit @ud) list=(list)] - ^- [total=@ud pages=@ud page=_list] - =/ l=@ud (lent list) - :+ l - %+ add (div l page-size) - (min 1 (mod l page-size)) - ?~ page list - %+ swag - [(mul u.page page-size) page-size] - list +++ on-init [~ this] +++ on-save !>(state) +++ on-load + |= old-vase=vase + ^- (quip card _this) + :_ this(state [%2 ~]) + :: TODO: leave all subscriptions + [%pass /connect %arvo %e %disconnect [~ /'~link']]~ :: -++ page-to-json - =, enjs:format - |* $: page-number=@ud - [total-items=@ud total-pages=@ud page=(list)] - item-to-json=$-(* json) - == - ^- json - %- pairs - :~ 'totalItems'^(numb total-items) - 'totalPages'^(numb total-pages) - 'pageNumber'^(numb page-number) - 'page'^a+(turn page item-to-json) - == -++ do-poke - |= [app=term =mark =vase] - ^- card - [%pass /create/[app]/[mark] %agent [our.bowl app] %poke mark vase] -:: -++ joined-group - |= [host=ship rid=resource] - ^- (list card) - =/ =path - (en-path:resource rid) - :~ - :: sync the group - :: - %^ do-poke %group-pull-hook - %pull-hook-action - !> ^- action:pull-hook - [%add host rid] - :: - :: sync the metadata - :: - %^ do-poke %metadata-hook - %metadata-hook-action - !> ^- metadata-hook-action:metadata-hook - [%add-synced host path] - :: - :: sync the collection - :: - %^ do-poke %link-listen-hook - %link-listen-action - !> ^- action:listen-hook - [%watch ~[name.rid]] - == -:: -++ handle-invite-update - |= upd=invite-update - ^- (list card) - ?. ?=(%accepted -.upd) ~ - ?. =(/link path.upd) ~ - =/ rid=resource - (de-path:resource path.invite.upd) - :~ :: add self - :* %pass - [%join-group (scot %p ship.invite.upd) path.invite.upd] - %agent [entity.rid %group-push-hook] - %poke %group-update - !> ^- action:group-store - [%add-members rid (sy our.bowl ~)] - == == -:: -++ handle-action - |= =action:store - ^- card - [%pass /action %agent [our.bowl %link-store] %poke %link-action !>(action)] -:: -++ handle-view-action - |= act=action:view - ^- (list card) - ?- -.act - %create (handle-create +.act) - %delete (handle-delete +.act) - %invite (handle-invite +.act) - == -:: -++ handle-create - |= [=path title=@t description=@t members=create-members:view real-group=?] - ^- (list card) - =/ group-path=^path - ?- -.members - %group path.members - :: - %ships - [%ship (scot %p our.bowl) path] - == - =; group-setup=(list card) - %+ weld group-setup - :~ :: add collection to metadata-store - :: - %^ do-poke %metadata-hook - %metadata-action - !> ^- metadata-action:md - :^ %add group-path - [%link path] - %* . *metadata:md - title title - description description - date-created now.bowl - creator our.bowl - == - :: - :: expose the metadata - :: - %^ do-poke %metadata-hook - %metadata-hook-action - !> ^- metadata-hook-action:metadata-hook - [%add-owned group-path] - :: - :: watch the collection ourselves - :: - %^ do-poke %link-listen-hook - %link-listen-action - !> ^- action:listen-hook - [%watch path] - == - ?: ?=(%group -.members) ~ - :: if the group is "real", make contact-view do the heavy lifting - =/ rid=resource - (de-path:resource group-path) - ?: real-group - :- %^ do-poke %contact-view - %contact-view-action - !> ^- contact-view-action:contact-view - [%groupify rid title description] - %+ turn ~(tap in ships.members) - |= =ship - ^- card - %^ do-poke %invite-hook - %invite-action - !> ^- invite-action - :^ %invite /link - (sham group-path eny.bowl) - :* our.bowl - %group-hook - group-path - ship - title - == - :: for "unmanaged" groups, do it ourselves - :: - =/ =policy - [%invite ships.members] - :* :: create the new group - :: - %^ do-poke %group-store - %group-action - !> ^- action:group-store - [%add-group rid policy %.y] - :: - :: send invites - :: - %+ turn ~(tap in ships.members) - |= =ship - ^- card - %^ do-poke %invite-hook - %invite-action - !> ^- invite-action - :^ %invite /link - (sham group-path eny.bowl) - :* our.bowl - %group-hook - group-path - ship - title - == - == -:: -++ handle-delete - |= =path - ^- (list card) - =/ groups=(list ^path) - (groups-from-resource:md [%link path]) - %- zing - %+ turn groups - |= =group=^path - =/ rid=resource - (de-path:resource group-path) - %+ snoc - ^- (list card) - :: if it's a real group, we can't/shouldn't unsync it. this leaves us with - :: no way to stop propagation of collection deletion. - :: - ?. ?=([%'~' ^] group-path) ~ - :: if it's an unmanaged group, we just stop syncing the group & metadata, - :: and clean up the group (after un-hooking it, to not push deletion). - :: - :~ %^ do-poke %group-hook - %group-hook-action - !> ^- action:group-hook - [%remove rid] - :: - %^ do-poke %metadata-hook - %metadata-hook-action - !> ^- metadata-hook-action:metadata-hook - [%remove group-path] - :: - %^ do-poke %group-store - %group-action - !> ^- action:group-store - [%remove-group rid ~] - == - :: remove collection from metadata-store - :: - %^ do-poke %metadata-store - %metadata-action - !> ^- metadata-action:md - [%remove group-path [%link path]] -:: -++ handle-invite - |= [=path ships=(set ship)] - ^- (list card) - %- zing - %+ turn (groups-from-resource:md %link path) - |= =group=^path - ^- (list card) - =/ rid=resource - (de-path:resource group-path) - =/ =group - (need (scry-group:grp rid)) - %- zing - :~ - ?. ?=(%invite -.policy.group) - ~ - :~ %^ do-poke %group-store - %group-action - !> ^- action:group-store - [%change-policy rid %invite %add-invites ships] - == - :: - %+ turn ~(tap in ships) - |= =ship - ^- card - %^ do-poke %invite-hook - %invite-action - !> ^- invite-action - :^ %invite /link - (sham group-path eny.bowl) - :* our.bowl - %group-pull-hook - group-path - ship - (rsh 3 1 (spat path)) - == - == -:: +give-tile-data: total unread count as json object -:: -::NOTE the full recalc of totals here probably isn't the end of the world. -:: but in case it is, well, here it is. -:: -++ give-tile-data - ^- card - =; =json - [%give %fact ~[/tile] %json !>(json)] - %+ frond:enjs:format 'unseen' - %- numb:enjs:format - %- %~ rep in - (scry-for (jug path url) /unseen) - |= [[=path unseen=(set url)] total=@ud] - %+ add total - ~(wyt in unseen) -:: -:: +give-initial-submissions: page of submissions on path -:: -:: for the / path, give page for every path -:: -:: result is in the shape of: { -:: "/some/path": { -:: totalItems: 1, -:: totalPages: 1, -:: pageNumber: 0, -:: page: [ -:: { commentCount: 1, ...restOfTheSubmission } -:: ] -:: }, -:: "/maybe/more": { etc } -:: } -:: -++ give-initial-submissions - ~/ %link-view-initial-submissions - |= [p=@ud =requested=path] - ^- (list card) - :_ :: only keep the base case alive (for updates), kick all others - :: - ?: &(=(0 p) ?=(~ requested-path)) ~ - [%give %kick ~ ~]~ - =; =json - [%give %fact ~ %json !>(json)] - %+ frond:enjs:format 'link-update' - %+ frond:enjs:format 'initial-submissions' - %- pairs:enjs:format - %+ turn - %~ tap by - %+ scry-for (map path submissions) - [%submissions requested-path] - |= [=path =submissions] - ^- [@t json] - :- (spat path) - =; =json - :: add unseen count - :: - ?> ?=(%o -.json) - :- %o - %+ ~(put by p.json) 'unseenCount' - %- numb:enjs:format - %~ wyt in - %+ scry-for (set url) - [%unseen path] - ?: &(=(0 p) ?=(~ requested-path)) - :: for a broad-scope initial result, only give total counts - :: - =, enjs:format - %- pairs - =+ l=(lent submissions) - :~ 'totalItems'^(numb l) - 'totalPages'^(numb (div l page-size)) - == - %^ page-to-json p - %+ get-paginated `p - submissions - |= =submission - ^- json - =/ =json (submission:enjs:store submission) - ?> ?=([%o *] json) - :: add in seen status - :: - =. p.json - %+ ~(put by p.json) 'seen' - :- %b - %+ scry-for ? - [%seen (build-discussion-path:store path url.submission)] - :: add in comment count - :: - =; comment-count=@ud - :- %o - %+ ~(put by p.json) 'commentCount' - (numb:enjs:format comment-count) - %- lent - ~| [path url.submission] - ^- comments - =- (~(got by (~(got by -) path)) url.submission) - %+ scry-for (per-path-url comments) - :- %discussions - (build-discussion-path:store path url.submission) -:: -++ give-specific-submission - |= [n=@ud =path =url] - :_ [%give %kick ~ ~]~ - =; =json - [%give %fact ~ %json !>(json)] - %+ frond:enjs:format 'link-update' - %+ frond:enjs:format 'submission' - ^- json - =; sub=(unit submission) - ?~ sub ~ - (submission:enjs:store u.sub) - =/ =submissions - =- (~(got by -) path) - %+ scry-for (map ^path submissions) - [%submissions path] - |- - ?~ submissions ~ - =* sub i.submissions - ?. =(url.sub url) - $(submissions t.submissions) - ?: =(0 n) `sub - $(n (dec n), submissions t.submissions) -:: -++ give-initial-discussions - |= [p=@ud =path =url] - ^- (list card) - :_ ?: =(0 p) ~ - [%give %kick ~ ~]~ - =; =json - [%give %fact ~ %json !>(json)] - %+ frond:enjs:format 'link-update' - %+ frond:enjs:format 'initial-discussions' - %^ page-to-json p - %+ get-paginated `p - =- (~(got by (~(got by -) path)) url) - %+ scry-for (per-path-url comments) - [%discussions (build-discussion-path:store path url)] - comment:enjs:store -:: -++ send-update - |= =update:store - ^- card - ?+ -.update ~|([dap.bowl %unexpected-update -.update] !!) - %submissions - %+ give-json - %+ frond:enjs:format 'link-update' - (update:enjs:store update) - :~ /json/0/submissions - (weld /json/0/submissions path.update) - == - :: - %discussions - %+ give-json - %+ frond:enjs:format 'link-update' - (update:enjs:store update) - :_ ~ - %+ weld /json/0/discussions - (build-discussion-path:store [path url]:update) - :: - %observation - %+ give-json - %+ frond:enjs:format 'link-update' - (update:enjs:store update) - ~[/json/seen] - == -:: -++ give-json - |= [=json paths=(list path)] - ^- card - [%give %fact paths %json !>(json)] -:: -++ scry-for - |* [=mold =path] - .^ mold - %gx - (scot %p our.bowl) - %link-store - (scot %da now.bowl) - (snoc `^path`path %noun) - == +++ on-poke on-poke:def +++ on-watch on-watch:def +++ on-agent on-agent:def +++ on-arvo on-arvo:def +++ on-peek on-peek:def +++ on-leave on-leave:def +++ on-fail on-fail:def -- From 1a419895a32d596313b79ed8efcf46ede077ab0b Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Wed, 19 Aug 2020 16:27:08 -0700 Subject: [PATCH 08/43] link-hooks: left TODO comments --- pkg/arvo/app/link-listen-hook.hoon | 1 + pkg/arvo/app/link-proxy-hook.hoon | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/arvo/app/link-listen-hook.hoon b/pkg/arvo/app/link-listen-hook.hoon index feb5ffb1e..5c1fade7c 100644 --- a/pkg/arvo/app/link-listen-hook.hoon +++ b/pkg/arvo/app/link-listen-hook.hoon @@ -29,6 +29,7 @@ ++ on-load |= =vase ^- (quip card _this) + :: TODO: get rid of all subscriptions in bowl :_ this [%pass /groups %agent [our.bowl %group-store] %leave ~]~ :: diff --git a/pkg/arvo/app/link-proxy-hook.hoon b/pkg/arvo/app/link-proxy-hook.hoon index ffa822ee6..0eab5a392 100644 --- a/pkg/arvo/app/link-proxy-hook.hoon +++ b/pkg/arvo/app/link-proxy-hook.hoon @@ -27,6 +27,7 @@ ++ on-load |= old-vase=vase ^- (quip card _this) + :: TODO: get rid of all subscriptions in bowl :_ this [%pass /groups %agent [our.bowl %group-store] %leave ~]~ :: From 4b26b2dd7115f933698cbd74c436099e873e4e55 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 1 Sep 2020 13:57:19 -0400 Subject: [PATCH 09/43] link: archive graph on migration --- pkg/arvo/app/link-store.hoon | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/pkg/arvo/app/link-store.hoon b/pkg/arvo/app/link-store.hoon index 0253b413f..485be958d 100644 --- a/pkg/arvo/app/link-store.hoon +++ b/pkg/arvo/app/link-store.hoon @@ -101,13 +101,15 @@ :_ this(state *state-1) =/ orm orm:graph-store |^ ^- (list card) - %+ murn ~(tap by by-group.s) + %- zing + %+ turn ~(tap by by-group.s) |= [=path =links] - ^- (unit card) + ^- (list card) ?. ?=([@ @ *] path) (on-bad-path path links) - :- ~ - %+ add-graph `resource`[(slav %p i.path) i.t.path] + =/ =resource [(slav %p i.path) i.t.path] + :_ [(archive-graph resource)]~ + %+ add-graph resource ^- graph:gra %+ gas:orm ~ =/ comments (~(gut by discussions.s) path *(map url discussion)) @@ -155,11 +157,21 @@ ++ add-graph |= [=resource =graph:gra] ^- card - =- [%pass /migrate-link %agent [our.bowl %graph-store] -] - ^- task:agent:gall - :+ %poke %graph-update - !> ^- update:gra + %- poke-graph-store [%0 now.bowl %add-graph resource graph `%graph-validator-link] + :: + ++ archive-graph + |= =resource + ^- card + %- poke-graph-store + [%0 now.bowl %archive-graph resource] + :: + ++ poke-graph-store + |= =update:gra + ^- card + :* %pass /migrate-link %agent [our.bowl %graph-store] + %poke %graph-update !>(update) + == -- :: ++ on-poke on-poke:def From 5608a7c4b7ac425edc2dfb34bba60d6fcb3829f6 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 1 Sep 2020 15:29:55 -0400 Subject: [PATCH 10/43] interface: wip links frontend migration --- pkg/interface/src/views/apps/links/app.js | 57 +------------------ .../links/components/lib/channel-sidebar.js | 18 +----- .../apps/links/components/lib/group-item.js | 20 +++---- .../views/apps/links/components/skeleton.js | 3 +- 4 files changed, 15 insertions(+), 83 deletions(-) diff --git a/pkg/interface/src/views/apps/links/app.js b/pkg/interface/src/views/apps/links/app.js index 73b134a9e..64b1e1308 100644 --- a/pkg/interface/src/views/apps/links/app.js +++ b/pkg/interface/src/views/apps/links/app.js @@ -28,8 +28,6 @@ export class LinksApp extends Component { // preload spinner asset new Image().src = '/~landscape/img/Spinner.png'; - this.props.api.links.getPage('', 0); - this.props.subscription.startApp('link'); this.props.subscription.startApp('graph'); if (!this.props.sidebarShown) { this.props.api.local.sidebarToggle(); @@ -37,7 +35,6 @@ export class LinksApp extends Component { } componentWillUnmount() { - this.props.subscription.stopApp('link'); this.props.subscription.stopApp('graph'); } @@ -46,25 +43,17 @@ export class LinksApp extends Component { const contacts = props.contacts ? props.contacts : {}; const groups = props.groups ? props.groups : {}; const associations = props.associations ? props.associations : { link: {}, contacts: {} }; - const links = props.links ? props.links : {}; - const comments = props.linkComments ? props.linkComments : {}; - const seen = props.linksSeen ? props.linksSeen : {}; - const totalUnseen = _.reduce( - links, - (acc, collection) => acc + collection.unseenCount, - 0 - ); + const graphKeys = props.graphKeys || new Set([]); const invites = props.invites ? props.invites : {}; - const listening = props.linkListening; const { api, sidebarShown, hideAvatars, hideNicknames } = this.props; return ( <> - {totalUnseen > 0 ? `(${totalUnseen}) ` : ''}OS1 - Links + OS1 - Links @@ -94,8 +82,6 @@ export class LinksApp extends Component { invites={invites} groups={groups} sidebarShown={sidebarShown} - links={links} - listening={listening} api={api} > { + console.log(props.graphKeys); + [...props.graphKeys].map((path) => { const groupPath = props.associations.link[path] ? props.associations.link[path]['group-path'] : ''; @@ -70,23 +71,10 @@ export class ChannelsSidebar extends Component { linkMetadata={props.associations['link']} channels={channels} selected={props.selected} - links={props.links} /> ); }); - if (groupedChannels['/~/'] && groupedChannels['/~/'].length !== 0) { - groupedItems.unshift( - - ); - } + //TODO handle unmanaged links const activeClasses = (props.active === 'collections') ? ' ' : 'dn-s '; diff --git a/pkg/interface/src/views/apps/links/components/lib/group-item.js b/pkg/interface/src/views/apps/links/components/lib/group-item.js index 021463336..e32f92356 100644 --- a/pkg/interface/src/views/apps/links/components/lib/group-item.js +++ b/pkg/interface/src/views/apps/links/components/lib/group-item.js @@ -21,18 +21,14 @@ export class GroupItem extends Component { if (!meta) return null; const selected = (props.selected === each); - const unseenCount = props.links[each] - ? props.links[each].unseenCount - : 0; - return ( - - ); + return ( + + ); }); return (
diff --git a/pkg/interface/src/views/apps/links/components/skeleton.js b/pkg/interface/src/views/apps/links/components/skeleton.js index 20ce80a56..67b49a8ce 100644 --- a/pkg/interface/src/views/apps/links/components/skeleton.js +++ b/pkg/interface/src/views/apps/links/components/skeleton.js @@ -32,9 +32,8 @@ export class Skeleton extends Component { groups={props.groups} selected={props.selected} sidebarShown={props.sidebarShown} - links={props.links} - listening={props.listening} api={props.api} + graphKeys={props.graphKeys} />
Date: Fri, 4 Sep 2020 11:29:37 -0500 Subject: [PATCH 11/43] wip: style cleanup of sidebar and attempt at making new metadata entry --- pkg/interface/src/views/apps/links/app.js | 78 +++--- .../lib/{channels-item.js => channel-item.js} | 2 +- .../links/components/lib/channel-sidebar.js | 151 ++++++----- .../apps/links/components/lib/group-item.js | 69 +++-- .../src/views/apps/links/components/new.js | 241 +++--------------- .../views/apps/links/components/skeleton.js | 36 ++- 6 files changed, 187 insertions(+), 390 deletions(-) rename pkg/interface/src/views/apps/links/components/lib/{channels-item.js => channel-item.js} (94%) diff --git a/pkg/interface/src/views/apps/links/app.js b/pkg/interface/src/views/apps/links/app.js index 64b1e1308..0e44e9b4a 100644 --- a/pkg/interface/src/views/apps/links/app.js +++ b/pkg/interface/src/views/apps/links/app.js @@ -67,8 +67,7 @@ export class LinksApp extends Component { rightPanelHide={true} sidebarShown={sidebarShown} api={api} - graphKeys={graphKeys} - > + graphKeys={graphKeys}> ); @@ -83,11 +82,8 @@ export class LinksApp extends Component { groups={groups} sidebarShown={sidebarShown} api={api} - > + graphKeys={graphKeys}> @@ -127,8 +123,7 @@ export class LinksApp extends Component { groups={groups} selected={resourcePath} sidebarShown={sidebarShown} - api={api} - > + api={api}> + {...props} /> ); }} @@ -166,8 +160,7 @@ export class LinksApp extends Component { selected={resourcePath} sidebarShown={sidebarShown} popout={popout} - api={api} - > + api={api}> + {...props} /> ); }} @@ -207,21 +199,19 @@ export class LinksApp extends Component { sidebarShown={sidebarShown} sidebarHideMobile={true} popout={popout} - api={api} - > + api={api}> + {...props} + contacts={contactDetails} + page={page} + resourcePath={resourcePath} + resource={resource} + amOwner={amOwner} + popout={popout} + sidebarShown={sidebarShown} + api={api} + hideNicknames={hideNicknames} + hideAvatars={hideAvatars} /> ); }} @@ -250,24 +240,22 @@ export class LinksApp extends Component { sidebarShown={sidebarShown} sidebarHideMobile={true} popout={popout} - api={api} - > + api={api}> + {...props} + resource={resource} + page={page} + url={url} + linkIndex={index} + contacts={contactDetails} + resourcePath={resourcePath} + groupPath={resource['group-path']} + amOwner={amOwner} + popout={popout} + sidebarShown={sidebarShown} + api={api} + hideAvatars={hideAvatars} + hideNicknames={hideNicknames} /> ); }} diff --git a/pkg/interface/src/views/apps/links/components/lib/channels-item.js b/pkg/interface/src/views/apps/links/components/lib/channel-item.js similarity index 94% rename from pkg/interface/src/views/apps/links/components/lib/channels-item.js rename to pkg/interface/src/views/apps/links/components/lib/channel-item.js index 735cc79e8..bf17479db 100644 --- a/pkg/interface/src/views/apps/links/components/lib/channels-item.js +++ b/pkg/interface/src/views/apps/links/components/lib/channel-item.js @@ -2,7 +2,7 @@ import React, { Component } from 'react'; import { Link } from 'react-router-dom'; import { makeRoutePath } from '~/logic/lib/util'; -export class ChannelsItem extends Component { +export class ChannelItem extends Component { render() { const { props } = this; diff --git a/pkg/interface/src/views/apps/links/components/lib/channel-sidebar.js b/pkg/interface/src/views/apps/links/components/lib/channel-sidebar.js index 1885de971..556dad509 100644 --- a/pkg/interface/src/views/apps/links/components/lib/channel-sidebar.js +++ b/pkg/interface/src/views/apps/links/components/lib/channel-sidebar.js @@ -6,54 +6,52 @@ import SidebarInvite from '~/views/components/SidebarInvite'; import { Welcome } from './welcome'; import { alphabetiseAssociations } from '~/logic/lib/util'; -export class ChannelsSidebar extends Component { - // drawer to the left - - render() { - const { props } = this; - - const sidebarInvites = Object.keys(props.invites) - .map((uid) => { - return ( - props.api.invite.accept('/link', uid)} - onDecline={() => props.api.invite.decline('/link', uid)} - /> - ); - }); - - const associations = props.associations.contacts ? alphabetiseAssociations(props.associations.contacts) : {}; - - const groupedChannels = {}; - console.log(props.graphKeys); - [...props.graphKeys].map((path) => { - const groupPath = props.associations.link[path] ? - props.associations.link[path]['group-path'] : ''; - - - if (groupPath in associations) { - if (groupedChannels[groupPath]) { - const array = groupedChannels[groupPath]; - array.push(path); - groupedChannels[groupPath] = array; - } else { - groupedChannels[groupPath] = [path]; - } - } else { - if (groupedChannels['/~/']) { - const array = groupedChannels['/~/']; - array.push(path); - groupedChannels['/~/'] = array; - } else { - groupedChannels['/~/'] = [path]; - }; - } +export const ChannelSidebar = (props) => { + const sidebarInvites = Object.keys(props.invites) + .map((uid) => { + return ( + props.api.invite.accept('/link', uid)} + onDecline={() => props.api.invite.decline('/link', uid)} + /> + ); }); - let i = -1; - const groupedItems = Object.keys(associations) + const associations = props.associations.contacts ? + alphabetiseAssociations(props.associations.contacts) : {}; + + const groupedChannels = {}; + console.log(props.graphKeys); + [...props.graphKeys].map((path) => { + console.log(props.associations.link); + const groupPath = props.associations.link[path] ? + props.associations.link[path]['group-path'] : ''; + + if (groupPath in associations) { + if (groupedChannels[groupPath]) { + const array = groupedChannels[groupPath]; + array.push(path); + groupedChannels[groupPath] = array; + } else { + groupedChannels[groupPath] = [path]; + } + } else { + if (groupedChannels['/~/']) { + const array = groupedChannels['/~/']; + array.push(path); + groupedChannels['/~/'] = array; + } else { + groupedChannels['/~/'] = [path]; + }; + } + }); + + let i = -1; + //TODO handle unmanaged links + + const groupedItems = Object.keys(associations) .map((each) => { const channels = groupedChannels[each]; if (!channels || channels.length === 0) @@ -74,40 +72,37 @@ export class ChannelsSidebar extends Component { /> ); }); - //TODO handle unmanaged links - const activeClasses = (props.active === 'collections') ? ' ' : 'dn-s '; + const activeClasses = (props.active === 'collections') ? ' ' : 'dn-s '; - let hiddenClasses = true; + let hiddenClasses = true; - if (props.popout) { - hiddenClasses = false; - } else { - hiddenClasses = props.sidebarShown; - } - - return ( -
-
-
- - New Collection - -
- - {sidebarInvites} - {groupedItems} -
-
- ); + if (props.popout) { + hiddenClasses = false; + } else { + hiddenClasses = props.sidebarShown; } -} + + return ( +
+
+
+ + New Collection + +
+ + {sidebarInvites} + {groupedItems} +
+
+ ); +}; diff --git a/pkg/interface/src/views/apps/links/components/lib/group-item.js b/pkg/interface/src/views/apps/links/components/lib/group-item.js index e32f92356..8160abba2 100644 --- a/pkg/interface/src/views/apps/links/components/lib/group-item.js +++ b/pkg/interface/src/views/apps/links/components/lib/group-item.js @@ -1,42 +1,39 @@ import React, { Component } from 'react'; -import { ChannelsItem } from './channels-item'; +import { ChannelItem } from './channel-item'; -export class GroupItem extends Component { - render() { - const { props } = this; - const association = props.association ? props.association : {}; +export const GroupItem = (props) => { + const association = props.association ? props.association : {}; - let title = association['app-path'] ? association['app-path'] : 'Unmanaged Collections'; + let title = + association['app-path'] ? association['app-path'] : 'Unmanaged Collections'; - if (association.metadata && association.metadata.title) { - title = association.metadata.title !== '' - ? association.metadata.title : title; - } - - const channels = props.channels ? props.channels : []; - const first = (props.index === 0) ? 'pt1' : 'pt6'; - - const channelItems = channels.map((each, i) => { - const meta = props.linkMetadata[each]; - if (!meta) - return null; - const selected = (props.selected === each); - return ( - - ); - }); - return ( -
-

{title}

- {channelItems} -
- ); + if (association.metadata && association.metadata.title) { + title = association.metadata.title !== '' + ? association.metadata.title : title; } -} -export default GroupItem; + const channels = props.channels ? props.channels : []; + const first = (props.index === 0) ? 'pt1' : 'pt6'; + + const channelItems = channels.map((each, i) => { + const meta = props.linkMetadata[each]; + if (!meta) { return null; } + const selected = (props.selected === each); + return ( + + ); + }); + + return ( +
+

{title}

+ {channelItems} +
+ ); +}; + diff --git a/pkg/interface/src/views/apps/links/components/new.js b/pkg/interface/src/views/apps/links/components/new.js index 3d32dff26..aa88ef595 100644 --- a/pkg/interface/src/views/apps/links/components/new.js +++ b/pkg/interface/src/views/apps/links/components/new.js @@ -5,215 +5,36 @@ import { Link } from 'react-router-dom'; import { makeRoutePath, deSig } from '~/logic/lib/util'; import urbitOb from 'urbit-ob'; -export class NewScreen extends Component { - constructor(props) { - super(props); - this.state = { - title: '', - description: '', - idName: '', - groups: [], - ships: [], - idError: false, - inviteError: false, - createGroup: false, - disabled: false - }; +export const NewScreen = (props) => { + const onClickCreate = () => { - this.titleChange = this.titleChange.bind(this); - this.descriptionChange = this.descriptionChange.bind(this); - this.setInvite = this.setInvite.bind(this); - } - - componentDidUpdate(prevProps, prevState) { - const { props, state } = this; - - if (prevProps !== props) { - const target = `/${state.idName}`; - if (target in props.associations) { - props.history.push(makeRoutePath(target)); - } - } - } - - titleChange(event) { - const asciiSafe = event.target.value.toLowerCase() - .replace(/[^a-z0-9-]/g, '-'); - this.setState({ - idName: asciiSafe + '-' + Math.floor(Math.random()*10000), // uniqueness - title: event.target.value - }); - } - - descriptionChange(event) { - this.setState({ - description: event.target.value - }); - } - - setInvite(value) { - this.setState({ - groups: value.groups, - ships: value.ships - }); - } - - onClickCreate() { - const { props, state } = this; - - if (!state.title) { - this.setState({ - idError: true, - inviteError: false - }); - return; - } - - const appPath = `/${state.idName}`; - - if (appPath in props.associations) { - this.setState({ - inviteError: false, - idError: true, - success: false - }); - return; - } - - let isValid = true; - const aud = state.ships.map(mem => `~${deSig(mem.trim())}`); - aud.forEach((mem) => { - if (!urbitOb.isValidPatp(mem)) { - isValid = false; - } - }); - - if (!isValid) { - this.setState({ - inviteError: true, - idError: false, - success: false - }); - return; - } - - const target = state.groups.length === 0 - ? { ships: aud } - : { group: state.groups[0] }; - - if (this.textarea) { - this.textarea.value = ''; - } - - this.setState({ - error: false, - success: true, - group: [], - ships: [], - disabled: true - }, () => { - const submit = props.api.links.createCollection( - appPath, - state.title, - state.description, - target, - state.createGroup - ); - submit.then(() => { - this.setState({ disabled: false }); - props.history.push(makeRoutePath(appPath)); - }); - }); - } - - render() { - const { props, state } = this; - - const createClasses = state.idName - ? 'pointer db f9 mt7 green2 bg-gray0-d ba pv3 ph4 b--green2' - : 'pointer db f9 mt7 gray2 ba bg-gray0-d pa2 pv3 ph4 b--gray3'; - - const idClasses = - 'f7 ba b--gray3 b--gray2-d bg-gray0-d white-d pa3 db w-100 ' + - 'focus-b--black focus-b--white-d '; - - let idErrElem = (); - if (state.idError) { - idErrElem = ( - - Collection must have a valid name. - - ); - } - - return ( -
-
- {'⟵ All Collections'} -
-

New Collection

-
-

Name

-