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

154 lines
3.7 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)
++ watch-preview
|= rid=resource
^- card
=/ =path
preview+(en-path:resource rid)
=/ =dock
[entity.rid %metadata-push-hook]
[%pass path %agent dock %watch path]
::
++ 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) ~
(watch-preview resource.invite.update)^~
::
%kick [watch-invites^~ state]
==
::
++ take-preview
|= [=wire =sign:agent:gall]
^- (quip card _state)
?> ?=([%preview @ *] wire)
=/ rid=resource
(de-path:resource t.wire)
?+ -.sign (on-agent:def wire sign)
%fact
?> =(%metadata-update p.cage.sign)
=+ !<(upd=metadata-update q.cage.sign)
?> ?=(%preview -.upd)
:_ state(previews (~(put by previews) rid +.upd))
:~ [%give %fact ~[wire] cage.sign]
[%give %kick ~[wire] ~]
==
::
%watch-ack
:_ state
?~ p.sign ~
:~ [%give %fact ~[wire] tang+!>(u.p.sign)]
[%give %kick ~[wire] ~]
==
==
--
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
?: =(1 1) `this
2021-01-21 08:18:13 +03:00
=+ !<(old=state-zero vase)
:_ this(state old)
?: (~(has by wex.bowl) [/invites our.bowl %invite-store]) ~
watch-invites^~
2021-01-21 08:18:13 +03:00
::
2021-01-13 07:50:37 +03:00
++ on-poke on-poke:def
++ on-agent
|= [=wire =sign:agent:gall]
=^ cards state
?+ wire (on-agent:def:hc wire sign)
[%invites ~] (take-invites:hc sign)
[%preview @ @ @ ~] (take-preview:hc wire sign)
==
[cards this]
::
++ on-watch
|= =path
?> (team:title [our src]:bowl)
?. ?=([%preview @ @ @ ~] path)
(on-watch:def path)
=/ rid=resource
(de-path:resource t.path)
2021-01-21 08:18:13 +03:00
=/ prev=(unit group-preview)
(~(get by previews) rid)
:_ this
2021-01-21 08:18:13 +03:00
?^ prev
:~ [%give %fact ~ metadata-update+!>([%preview u.prev])]
[%give %kick ~ ~]
==
=/ =dock
[entity.rid %metadata-push-hook]
2021-01-21 08:18:13 +03:00
[%pass path %agent dock %watch path]~
::
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]
^- (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
^- (unit path)
`/
--