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

227 lines
5.2 KiB
Plaintext
Raw Normal View History

:: chat-hook [landscape]:
:: mirror chat data from foreign to local based on read
2019-11-23 01:05:06 +03:00
:: allow sending chat messages to foreign paths based on write perms
::
/- inv=invite-store, *metadata-store, *group-store,
2020-12-11 06:41:25 +03:00
hook=chat-hook, *group, push-hook, pull-hook, store=chat-store
/+ default-agent, verb, dbug, group-store, grpl=group,
resource, graph-store, *migrate
2019-11-23 01:05:06 +03:00
|%
+$ card card:agent:gall
::
+$ versioned-state
2020-12-11 06:41:25 +03:00
$% state-10
2020-12-03 08:14:27 +03:00
state-11
2020-06-24 03:28:57 +03:00
==
::
2020-12-11 06:41:25 +03:00
+$ migration-state (map resource @ud)
2020-12-03 08:14:27 +03:00
+$ state-11 [%11 state-base migrate=migration-state]
2020-10-02 04:45:20 +03:00
+$ state-10 [%10 state-base]
+$ state-base
2020-04-29 11:36:12 +03:00
$: =synced:hook
2019-11-23 01:05:06 +03:00
invite-created=_|
allow-history=(map path ?)
==
--
2020-12-03 08:14:27 +03:00
=| state-11
2019-11-23 01:05:06 +03:00
=* state -
::
%- agent:dbug
2020-04-03 00:43:03 +03:00
%+ verb |
2019-11-23 01:05:06 +03:00
^- agent:gall
=<
|_ bol=bowl:gall
2019-11-23 01:05:06 +03:00
+* this .
chat-core +>
cc ~(. chat-core bol)
def ~(. (default-agent this %|) bol)
2019-11-23 01:05:06 +03:00
::
++ on-init
^- (quip card _this)
:_ this(invite-created %.y)
[(invite-poke:cc [%create %chat]) ~]
2019-11-23 01:05:06 +03:00
++ on-save !>(state)
++ on-load
|= old-vase=vase
^- (quip card _this)
|^
=/ old !<(versioned-state old-vase)
2020-06-24 03:28:57 +03:00
=| cards=(list card)
|-
2020-12-03 08:14:27 +03:00
?: ?=(%11 -.old)
2020-06-24 03:28:57 +03:00
[cards this(state old)]
2020-12-11 06:41:25 +03:00
=. cards
:_ cards
=- [%pass /self-poke %agent [our.bol %chat-hook] %poke -]
noun+!>(%migrate-graph)
$(old [%11 +.old ~])
--
2019-11-23 01:05:06 +03:00
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
=^ cards state
?+ mark (on-poke:def mark vase)
%noun
2020-12-03 07:52:02 +03:00
%- poke-noun:cc
2020-12-11 06:41:25 +03:00
!< ?(%migrate-graph)
2020-12-03 07:52:02 +03:00
vase
2020-12-01 00:07:51 +03:00
::
%import
?> (team:title our.bol src.bol)
(poke-import:cc q.vase)
2019-11-23 01:05:06 +03:00
==
[cards this]
::
2020-12-11 06:41:25 +03:00
++ on-watch on-watch:def
2019-11-23 01:05:06 +03:00
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card _this)
2020-12-03 08:14:27 +03:00
|^
?. ?=([%migrate-graph *] wire)
2020-12-10 05:36:26 +03:00
`this
2020-12-03 08:14:27 +03:00
=/ rid=resource
(de-path:resource t.wire)
?. ?=(%watch-ack -.sign)
~| "Expected error, please ignore"
(on-agent:def wire sign)
?~ p.sign
:_ this(migrate (~(del by migrate) rid))
~[(poke-graph-pull-hook %add entity.rid rid)]
=/ nack-count=@ud
+((~(gut by migrate) rid 0))
?: (gte nack-count 24)
~& >>> "failed to migrate notebook {<rid>} to graph-store"
[~ this]
:_ this(migrate (~(put by migrate) rid nack-count))
=/ wakeup=@da
(add now.bol (mul ~s1 (bex (min 19 nack-count))))
[%pass wire %arvo %b %wait wakeup]~
2019-11-23 01:05:06 +03:00
::
2020-12-03 08:14:27 +03:00
++ poke-graph-pull-hook
|= =action:pull-hook
^- card
=- [%pass / %agent [our.bol %graph-pull-hook] %poke -]
pull-hook-action+!>(action)
--
2019-11-23 01:05:06 +03:00
::
++ on-leave on-leave:def
2020-12-11 06:41:25 +03:00
++ on-peek on-peek:def
2020-12-03 08:14:27 +03:00
++ on-arvo
|= [=wire =sign-arvo]
^- (quip card _this)
?+ wire (on-arvo:def wire sign-arvo)
[%migrate-graph *]
=/ rid=resource
(de-path:resource t.wire)
?> ?=([%behn %wake *] sign-arvo)
~? ?=(^ error.sign-arvo)
"behn errored in backoff timers, continuing anyway"
:_ this
~[(watch-graph:cc rid)]
==
2019-11-23 01:05:06 +03:00
++ on-fail on-fail:def
--
::
|_ bol=bowl:gall
2020-05-25 08:52:54 +03:00
++ grp ~(. grpl bol)
2020-12-03 08:14:27 +03:00
++ watch-graph
|= rid=resource
^- card
=/ =path
(en-path:resource rid)
[%pass migrate-graph+path %agent [entity.rid %graph-push-hook] %watch resource+path]
2019-11-23 01:05:06 +03:00
::
++ poke-noun
2020-12-11 06:41:25 +03:00
|= a=?(%migrate-graph)
^- (quip card _state)
|^
?- a
2020-12-03 07:52:02 +03:00
%migrate-graph migrate-graph
==
::
2020-12-03 07:52:02 +03:00
++ poke-our
|= [app=term =cage]
^- card
[%pass / %agent [our.bol app] %poke cage]
::
++ poke-graph-push-hook
|= =action:push-hook
^- card
(poke-our %graph-push-hook %push-hook-action !>(action))
::
++ poke-graph-store
|= =update:graph-store
^- card
(poke-our %graph-store %graph-update-2 !>(update))
2020-12-03 07:52:02 +03:00
::
2020-12-11 06:41:25 +03:00
++ nobody
^- @p
(bex 128)
::
++ path-to-resource
|= =path
^- resource
?. ?=([@ @ ~] path)
nobody^(spat path)
=/ m-ship=(unit ship)
(slaw %p i.path)
?~ m-ship
nobody^(spat path)
[u.m-ship i.t.path]
::
2020-12-03 07:52:02 +03:00
++ migrate-graph
^- (quip card _state)
2020-12-03 08:14:27 +03:00
=/ syncs=(list [=path =ship])
2020-12-03 07:52:02 +03:00
~(tap by synced)
2020-12-03 08:14:27 +03:00
=| cards=(list card)
|-
?~ syncs [cards state]
=, i.syncs
2020-12-03 07:52:02 +03:00
=/ rid=resource
2020-12-11 06:41:25 +03:00
(path-to-resource path)
2020-12-03 08:14:27 +03:00
~& migrating+path
~& to+rid
2020-12-11 06:41:25 +03:00
?: =(nobody entity.rid)
2020-12-03 08:14:27 +03:00
%_ $
syncs t.syncs
::
cards
:_ cards
%- poke-graph-store
:- now.bol
2020-12-03 08:14:27 +03:00
archive-graph+rid
==
2020-12-03 07:52:02 +03:00
?: =(our.bol ship)
2020-12-03 08:14:27 +03:00
%_ $
cards :_(cards (poke-graph-push-hook %add rid))
syncs t.syncs
==
%_ $
cards :_(cards (watch-graph rid))
syncs t.syncs
migrate (~(put by migrate) rid 0)
==
--
::
2020-12-01 00:07:51 +03:00
++ poke-import
|= arc=*
^- (quip card _state)
=/ sty=state-11
:+ %11
:+ (remake-map ;;((tree [path ship]) +<.arc))
;;(? +>-.arc)
2020-12-02 12:32:25 +03:00
(remake-map ;;((tree [path ?]) +>+.arc))
~
2020-12-01 00:07:51 +03:00
:_ sty
:_ ~
=- [%pass /self-poke %agent [our.bol %chat-hook] %poke -]
noun+!>(%migrate-graph)
2020-12-01 00:07:51 +03:00
::
2019-11-23 01:05:06 +03:00
++ invite-poke
|= =action:inv
2019-11-23 01:05:06 +03:00
^- card
[%pass / %agent [our.bol %invite-store] %poke %invite-action !>(action)]
2019-11-23 01:05:06 +03:00
--