shrub/pkg/arvo/app/group-view.hoon

329 lines
7.9 KiB
Plaintext
Raw Normal View History

2021-01-29 07:52:36 +03:00
/- view-sur=group-view, group-store, *group, metadata=metadata-store
/+ default-agent, agentio, mdl=metadata,
resource, dbug, grpl=group, conl=contact, verb
2021-01-12 02:05:39 +03:00
|%
++ card card:agent:gall
::
2021-03-04 05:54:37 +03:00
+$ base-state-0
joining=(map rid=resource [=ship =progress:view])
::
2021-03-04 05:54:37 +03:00
+$ base-state-1
joining=(map rid=resource request:view)
::
2021-01-12 02:05:39 +03:00
+$ state-zero
2021-03-04 05:54:37 +03:00
[%0 base-state-0]
::
+$ state-one
2021-03-04 05:54:37 +03:00
[%1 base-state-0]
::
+$ state-two
[%2 base-state-1]
::
+$ versioned-state
$% state-zero
state-one
2021-03-04 05:54:37 +03:00
state-two
2021-01-12 02:05:39 +03:00
==
::
++ view view-sur
2021-01-12 02:05:39 +03:00
--
2021-03-04 05:54:37 +03:00
=| state-two
2021-01-12 02:05:39 +03:00
=* state -
::
%- agent:dbug
2021-01-29 08:12:50 +03:00
%+ verb |
2021-01-12 02:05:39 +03:00
^- agent:gall
=<
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
gc ~(. +> bowl)
io ~(. agentio bowl)
++ on-init
`this
++ on-save
!>(state)
::
++ on-load
|= =vase
=+ !<(old=versioned-state vase)
=| cards=(list card)
2021-03-04 05:54:37 +03:00
|^
?- -.old
%2 [cards this(state old)]
%1 $(-.old %2, +.old (base-state-to-1 +.old))
%0 $(-.old %1, cards :_(cards (poke-self:pass:io noun+!>(%cleanup))))
==
::
++ base-state-to-1
|= base-state-0
%- ~(gas by *(map resource request:view))
(turn ~(tap by joining) request-to-1)
::
++ request-to-1
|= [rid=resource =ship =progress:view]
^- [resource request:view]
:- rid
%* . *request:view
started now.bowl
hidden %.n
ship ship
progress progress
==
--
2021-01-12 02:05:39 +03:00
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
?: ?=(%noun mark)
=^ cards state
poke-noun:gc
[cards this]
?. ?=(%group-view-action mark)
2021-01-12 02:05:39 +03:00
(on-poke:def mark vase)
=+ !<(=action:view vase)
2021-01-12 02:05:39 +03:00
=^ cards state
2021-03-04 05:54:37 +03:00
?+ -.action !!
%join jn-abet:(jn-start:join:gc +.action)
%hide (hide:gc +.action)
==
2021-01-12 02:05:39 +03:00
[cards this]
::
++ on-watch
|= =path
?+ path (on-watch:def path)
[%all ~]
:_ this
:_ ~
%+ fact:io
:- %group-view-update
2021-03-04 05:54:37 +03:00
!>(`update:view`[%initial joining])
~
==
2021-01-12 02:05:39 +03:00
::
2021-01-29 08:12:50 +03:00
++ on-peek on-peek:def
2021-01-12 02:05:39 +03:00
::
++ on-agent
|= [=wire =sign:agent:gall]
=^ cards state
?+ wire `state
[%join %ship @ @ *]
=/ rid
(de-path:resource t.wire)
?. (~(has by joining) rid) `state
jn-abet:(jn-agent:(jn-abed:join:gc rid) t.t.t.t.wire sign)
2021-01-12 02:05:39 +03:00
==
[cards this]
::
2021-01-29 08:12:50 +03:00
++ on-arvo on-arvo:def
++ on-leave on-leave:def
++ on-fail on-fail:def
2021-01-12 02:05:39 +03:00
--
|_ =bowl:gall
++ met ~(. mdl bowl)
++ grp ~(. grpl bowl)
2021-01-12 02:05:39 +03:00
++ io ~(. agentio bowl)
++ con ~(. conl bowl)
2021-03-04 05:54:37 +03:00
++ hide
|= rid=resource
^- (quip card _state)
:- (fact:io group-view-update+!>([%hide rid]) /all ~)^~
state(joining (~(jab by joining) rid |=(request:view +<(hidden %.y))))
2021-01-12 02:05:39 +03:00
::
++ has-joined
|= rid=resource
=- ?=(^ -)
?~ grp=(peek-group:met %groups rid)
(peek-group:met %graph rid)
grp
::
++ poke-noun
^- (quip card _state)
2021-03-04 05:54:37 +03:00
=; new-joining=(map resource request:view)
`state(joining new-joining)
%+ roll ~(tap by joining)
2021-03-04 05:54:37 +03:00
|= [[rid=resource =request:view] out=_joining]
?. (has-joined rid) out
(~(del by out) rid)
2021-01-12 02:05:39 +03:00
::
++ join
|_ [rid=resource =ship cards=(list card)]
2021-01-12 02:05:39 +03:00
++ jn-core .
++ emit-many
|= crds=(list card)
jn-core(cards (weld (flop crds) cards))
::
++ emit
|= =card
jn-core(cards [card cards])
::
++ tx-progress
|= =progress:view
=. joining
2021-03-04 05:54:37 +03:00
(~(jab by joining) rid |=(request:view +<(progress progress)))
2021-01-29 07:52:36 +03:00
=; =cage
(emit (fact:io cage /all tx+(en-path:resource rid) ~))
group-view-update+!>([%progress rid progress])
::
++ watch-md
(emit (watch-our:(jn-pass-io /md) %metadata-store /updates))
::
++ watch-groups
(emit (watch-our:(jn-pass-io /groups) %group-store /groups))
::
2021-01-12 02:05:39 +03:00
++ jn-pass-io
|= pax=path
~(. pass:io (welp join+(en-path:resource rid) pax))
2021-01-12 02:05:39 +03:00
::
++ jn-abed
|= r=resource
2021-03-04 05:54:37 +03:00
=/ =request:view
(~(got by joining) r)
2021-03-04 05:54:37 +03:00
jn-core(rid r, ship ship.request)
2021-01-12 02:05:39 +03:00
::
++ jn-abet
^- (quip card _state)
[(flop cards) state]
::
2021-01-12 02:05:39 +03:00
++ jn-start
|= [rid=resource =^ship]
^+ jn-core
?< (~(has by joining) rid)
=. joining
2021-03-04 05:54:37 +03:00
(~(put by joining) rid [%.n now.bowl ship %start])
2021-01-12 02:05:39 +03:00
=. jn-core
(jn-abed rid)
?< ~|("already joined {<rid>}" (has-joined rid))
=. jn-core
%- emit
%+ poke:(jn-pass-io /add)
[ship %group-push-hook]
2021-03-18 06:53:57 +03:00
group-update-0+!>([%add-members rid (silt our.bowl ~)])
=. jn-core (tx-progress %start)
=> watch-md
watch-groups
2021-01-12 02:05:39 +03:00
::
++ jn-agent
|= [=wire =sign:agent:gall]
^+ jn-core
2021-01-12 02:05:39 +03:00
|^
?+ -.wire ~|("bad %join wire" !!)
%add :: join group
?> ?=(%poke-ack -.sign)
?^ p.sign
(cleanup %no-perms)
=> %- emit
2021-01-29 08:12:50 +03:00
%+ poke-our:(jn-pass-io /pull-groups) %group-pull-hook
pull-hook-action+!>([%add ship rid])
(tx-progress %added)
::
2021-01-12 02:05:39 +03:00
%pull-groups
?> ?=(%poke-ack -.sign)
(ack +.sign)
::
2021-01-12 02:05:39 +03:00
%groups
?+ -.sign !!
%fact (groups-fact +.sign)
%watch-ack (ack +.sign)
%kick watch-groups
2021-01-12 02:05:39 +03:00
==
::
2021-01-12 02:05:39 +03:00
%pull-md
?> ?=(%poke-ack -.sign)
(ack +.sign)
::
%pull-co
?> ?=(%poke-ack -.sign)
(ack +.sign)
::
%share-co
?> ?=(%poke-ack -.sign)
(ack +.sign)
::
%push-co
?> ?=(%poke-ack -.sign)
(ack +.sign)
::
2021-01-12 02:05:39 +03:00
%md
?+ -.sign !!
%fact (md-fact +.sign)
%watch-ack (ack +.sign)
%kick watch-md
2021-01-12 02:05:39 +03:00
==
::
%pull-graphs
2021-01-12 02:05:39 +03:00
?> ?=(%poke-ack -.sign)
%- cleanup
?^(p.sign %strange %done)
2021-01-12 02:05:39 +03:00
==
::
2021-01-12 02:05:39 +03:00
++ groups-fact
|= =cage
2021-03-11 07:05:50 +03:00
?. ?=(%group-update-0 p.cage) jn-core
2021-01-12 02:05:39 +03:00
=+ !<(=update:group-store q.cage)
?. ?=(%initial-group -.update) jn-core
?. =(rid resource.update) jn-core
%- emit-many
=/ cag=^cage pull-hook-action+!>([%add [entity .]:rid])
%- zing
:~ [(poke-our:(jn-pass-io /pull-md) %metadata-pull-hook cag)]~
[(poke-our:(jn-pass-io /pull-co) %contact-pull-hook cag)]~
::
?. scry-is-public:con ~
:_ ~
%+ poke:(jn-pass-io /share-co)
[entity.rid %contact-push-hook]
[%contact-share !>([%share our.bowl])]
==
2021-01-12 02:05:39 +03:00
::
++ md-fact
|= [=mark =vase]
2021-03-11 07:05:50 +03:00
?. ?=(%metadata-update-0 mark) jn-core
2021-01-29 07:52:36 +03:00
=+ !<(=update:metadata vase)
?. ?=(%initial-group -.update) jn-core
?. =(group.update rid) jn-core
=. jn-core (cleanup %done)
?. hidden:(need (scry-group:grp rid))
=/ list-md=(list [=md-resource:metadata =association:metadata])
%+ skim ~(tap by associations.update)
|= [=md-resource:metadata =association:metadata]
=(app-name.md-resource %groups)
?> ?=(^ list-md)
=* metadatum metadatum.association.i.list-md
?. ?& ?=(%group -.config.metadatum)
?=(^ feed.config.metadatum)
?=(^ u.feed.config.metadatum)
==
jn-core
=* feed resource.u.u.feed.config.metadatum
%- emit
%+ poke-our:(jn-pass-io /pull-feed) %graph-pull-hook
pull-hook-action+!>([%add [entity .]:feed])
%- emit-many
2021-01-29 07:52:36 +03:00
%+ murn ~(tap by associations.update)
|= [=md-resource:metadata =association:metadata]
^- (unit card)
2021-01-29 07:52:36 +03:00
?. =(app-name.md-resource %graph) ~
=* rid resource.md-resource
:- ~
%+ poke-our:(jn-pass-io /pull-graph) %graph-pull-hook
pull-hook-action+!>([%add [entity .]:rid])
2021-01-12 02:05:39 +03:00
::
++ ack
|= err=(unit tang)
?~ err jn-core
%- (slog u.err)
(cleanup %strange)
2021-01-12 02:05:39 +03:00
::
++ cleanup
|= =progress:view
=. jn-core
(tx-progress progress)
=. joining (~(del by joining) rid)
=. jn-core
(emit (leave-our:(jn-pass-io /groups) %group-store))
(emit (leave-our:(jn-pass-io /md) %metadata-store))
2021-01-12 02:05:39 +03:00
--
--
--