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

170 lines
3.6 KiB
Plaintext
Raw Normal View History

2020-02-15 03:31:52 +03:00
:: metadata-hook: allow syncing foreign metadata
::
2020-02-19 04:35:00 +03:00
/- *metadata-store, *metadata-hook
2020-02-15 03:31:52 +03:00
/+ default-agent
|%
+$ card card:agent:gall
::
++ versioned-state
$% state-zero
==
::
+$ state-zero
$: %0
2020-02-19 04:35:00 +03:00
synced=(map group-path ship)
2020-02-15 03:31:52 +03:00
==
--
=| state-zero
=* state -
^- agent:gall
=<
|_ =bowl:gall
+* this .
hook-core +>
hc ~(. hook-core bowl)
def ~(. (default-agent this %|) bowl)
::
2020-02-19 04:35:00 +03:00
++ on-init
[[%pass /updates %agent [our.bol %metadata-store] %watch /updates]~ this]
2020-02-15 03:31:52 +03:00
::
2020-02-19 04:35:00 +03:00
++ on-save !>(state)
++ on-load |=(=vase `this(state !<(state-zero vase)))
2020-02-15 03:31:52 +03:00
++ on-leave on-leave:def
++ on-peek on-peek:def
++ on-arvo on-arvo:def
++ on-fail on-fail:def
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
2020-02-19 04:35:00 +03:00
?+ mark (on-poke:def mark vase)
%metadata-hook-action
=^ cards state
(poke-hook-action:hc !<(metadata-hook-action vase))
[cards this]
==
2020-02-15 03:31:52 +03:00
::
++ on-watch
|= =path
^- (quip card _this)
2020-02-19 04:35:00 +03:00
?+ path (on-watch:def path)
[%group *] [(watch-group:cc t.path) this]
==
2020-02-15 03:31:52 +03:00
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card _this)
?+ -.sign (on-agent:def wire sign)
2020-02-19 04:35:00 +03:00
%kick
2020-02-15 03:31:52 +03:00
=^ cards state
2020-02-19 04:35:00 +03:00
(kick:hc wire)
2020-02-15 03:31:52 +03:00
[cards this]
::
2020-02-19 04:35:00 +03:00
%watch-ack
=^ cards state
(watch-ack:hc wire p.sign)
[cards this]
2020-02-15 03:31:52 +03:00
::
%fact
?+ p.cage.sign (on-agent:def wire sign)
%metadata-update
=^ cards state
2020-02-19 04:35:00 +03:00
(fact-metadata-update:hc wire !<(metadata-update q.cage.sign))
2020-02-15 03:31:52 +03:00
[cards this]
==
==
--
::
|_ bol=bowl:gall
2020-02-19 04:35:00 +03:00
++ poke-hook-action
|= act=metadata-hook-action
^- (quip card _state)
|^
?- -.act
%add-owned
?> (team:title our.bol src.bol)
:- ~
?: (~(has by synced) path.act) state
state(synced (~(put by synced) path.act our.bol))
::
%add-synced
?> (team:title our.bol src.bol)
=/ =path [%group path.act]
?: (~(has by synced) path.act) [~ state]
:_ state(synced (~(put by synced) path.act ship.act))
[%pass path %agent [ship.act %metadata-hook] %watch path]~
::
%remove
=/ ship (~(get by synced) path.act)
?~ ship [~ state]
?: &(!(u.ship our.bol) !(team.title our.bol src.bol))
[~ state]
:_ state(synced (~(del by synced) path.act))
%- zing
:~ (unsubscribe [%group path.act])
?. &(=(u.ship our.bol) (team:title our.bol src.bol)) ~
[%give %kick ~[[%group path.act]] ~]~
==
==
::
++ unsubscribe
|= pax=path
^- (list card)
?> ?=(^ pax)
=/ shp (~(get by synced) t.pax)
?~ shp ~
?: =(u.shp our.bol)
[%pass pax %agent [our.bol %chat-store] %leave ~]~
[%pass pax %agent [u.shp %chat-hook] %leave ~]~
--
::
++ watch-group
|= =path
^- (list card)
?> (~(has by synced) path)
~
::
++ fact-metadata-update
|= [wir=wire fact=metadata-update]
^- (quip card _state)
|^
[?:((team:title our.bol src.bol) handle-local handle-foreign) state]
::
++ handle-local
?+ -.fact ~
%add
~
::
%update-metadata
~
::
%remove
~
==
::
++ handle-foreign
?+ -.fact ~
%add
~
::
%update-metadata
~
::
%remove
~
==
--
::
++ kick
|= wir=wire
^- (quip card _state)
[~ state]
::
2020-02-15 03:31:52 +03:00
++ watch-ack
|= [wir=wire saw=(unit tang)]
^- (quip card _state)
2020-02-19 04:35:00 +03:00
?~ saw [~ state]
2020-02-15 03:31:52 +03:00
?> ?=(^ wir)
[~ state(synced (~(del by synced) t.wir))]
--