shrub/pkg/arvo/app/metadata-pull-hook.hoon

148 lines
3.5 KiB
Plaintext
Raw Normal View History

2021-01-13 07:50:37 +03:00
:: metadata-pull-hook [landscape]:
::
:: allow syncing group data from foreign paths to local paths
::
/- *group, invite-store, *metadata-store
2021-01-13 07:50:37 +03:00
/+ default-agent, verb, dbug, store=group-store, grpl=group, pull-hook
/+ resource, mdl=metadata
2021-01-13 07:50:37 +03:00
~% %group-hook-top ..part ~
|%
+$ card card:agent:gall
::
++ config
^- config:pull-hook
:* %metadata-store
metadata-update
%metadata-update
%metadata-push-hook
==
2021-01-21 08:18:13 +03:00
+$ state-zero
[%0 previews=(map resource group-preview)]
2021-01-13 07:50:37 +03:00
::
--
::
::
%- agent:dbug
%+ verb |
^- agent:gall
%- (agent:pull-hook config)
^- (pull-hook:pull-hook config)
2021-01-21 08:18:13 +03:00
=| state-zero
=* state -
=> |_ =bowl:gall
++ def ~(. (default-agent state %|) bowl)
++ get-preview
|= rid=resource
^- card
=/ =path
preview+(en-path:resource rid)
=/ =dock
[entity.rid %metadata-push-hook]
=/ =cage
metadata-hook-update+!>([%req-preview rid])
[%pass path %agent dock %poke cage]
::
++ watch-invites
^- card
[%pass /invites %agent [our.bowl %invite-store] %watch /updates]
::
++ take-invites
|= =sign:agent:gall
^- (quip card _state)
?+ -.sign (on-agent:def /invites sign)
%fact
?> ?=(%invite-update p.cage.sign)
=+ !<(=update:invite-store q.cage.sign)
:_ state
?. ?=(%invite -.update) ~
?. =(%contacts term.update) ~
(get-preview resource.invite.update)^~
::
%kick [watch-invites^~ state]
==
--
2021-01-13 07:50:37 +03:00
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
dep ~(. (default:pull-hook this config) bowl)
met ~(. mdl bowl)
hc ~(. +> bowl)
2021-01-13 07:50:37 +03:00
::
++ on-init on-init:def
2021-01-21 08:18:13 +03:00
++ on-save !>(state)
++ on-load
|= =vase
=+ !<(old=state-zero vase)
:_ this(state old)
?: (~(has by wex.bowl) [/invites our.bowl %invite-store]) ~
2021-01-26 04:46:06 +03:00
~[watch-invites:hc]
2021-01-21 08:18:13 +03:00
::
++ on-poke
|= [=mark =vase]
?. ?=(%metadata-hook-update mark)
(on-poke:def mark vase)
=+ !<(upd=metadata-hook-update vase)
?. ?=(%preview -.upd)
(on-poke:def mark vase)
:_ this(previews (~(put by previews) group.upd +.upd))
=/ paths=(list path)
~[preview+(en-path:resource group.upd)]
:~ [%give %fact paths mark^vase]
[%give %kick paths ~]
==
::
++ on-agent
|= [=wire =sign:agent:gall]
=^ cards state
?+ wire (on-agent:def:hc wire sign)
[%invites ~] (take-invites:hc sign)
::
[%preview @ @ @ ~]
?. ?=(%poke-ack -.sign)
(on-agent:def:hc wire sign)
:_ state
?~ p.sign ~
:~ [%give %fact ~[wire] tang+!>(u.p.sign)]
[%give %kick ~[wire] ~]
==
==
[cards this]
::
++ on-watch
|= =path
?> (team:title [our src]:bowl)
?. ?=([%preview @ @ @ ~] path)
(on-watch:def path)
=/ rid=resource
(de-path:resource t.path)
=/ prev=(unit group-preview)
(~(get by previews) rid)
:_ this
?~ prev
(get-preview rid)^~
[%give %fact ~ metadata-hook-update+!>([%preview u.prev])]~
::
2021-01-13 07:50:37 +03:00
++ on-leave on-leave:def
++ on-peek on-peek:def
2021-01-21 08:18:13 +03:00
++ on-arvo on-arvo:def
::
2021-01-13 07:50:37 +03:00
++ on-fail on-fail:def
++ on-pull-nack
|= [=resource =tang]
2021-01-13 07:50:37 +03:00
^- (quip card _this)
=/ =associations
(metadata-for-group:met resource)
:_ this
%+ turn ~(tap by associations)
|= [=md-resource =association]
=- [%pass / %agent [our.bowl %metadata-store] %poke -]
:- %metadata-update
!> ^- metadata-update
[%remove resource md-resource]
2021-01-13 07:50:37 +03:00
::
++ on-pull-kick
|= =resource
2021-01-13 07:50:37 +03:00
^- (unit path)
`/
--