shrub/pkg/landscape/app/hark-invite-hook.hoon

172 lines
4.1 KiB
Plaintext
Raw Normal View History

2021-09-06 06:31:11 +03:00
/- hark=hark-store, invite=invite-store
/+ verb, dbug, default-agent, agentio, resource, metadata=metadata-store
2021-09-06 06:31:11 +03:00
|%
+$ card card:agent:gall
+$ versioned-state
$% state-0
==
::
+$ state-0
$: blocked=(jug resource [uid=serial:invite =invite:invite])
~
==
2021-09-06 06:31:11 +03:00
--
2021-09-29 07:48:27 +03:00
%+ verb |
2021-09-06 06:31:11 +03:00
%- agent:dbug
^- agent:gall
=| state-0
=* state -
=<
2021-09-06 06:31:11 +03:00
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
io ~(. agentio bowl)
pass pass:io
cc ~(. +> bowl)
++ on-init
:_ this
~[watch:invite-store:cc]
2021-09-06 06:31:11 +03:00
::
++ on-load
|= =vase
:_ this
(drop safe-watch:invite-store:cc)
++ on-save !>(state)
2021-09-06 06:31:11 +03:00
::
++ on-poke on-poke:def
++ on-peek on-peek:def
++ on-watch on-watch:def
++ on-agent
|= [=wire =sign:agent:gall]
|^
?+ wire (on-agent:def wire sign)
[%invites ~] take-invites
::
[%groups @ @ @ ~]
=/ rid=resource (de-path:resource t.wire)
(take-groups rid)
2021-09-06 06:31:11 +03:00
==
++ take-groups
|= rid=resource
=/ blocking (~(get ju blocked) rid)
|^
?+ -.sign (on-agent:def wire sign)
::
%kick
?: =(~ blocking) `this
(flush-blocking (rap 3 (scot %p entity.rid) '/' name.rid ~))
::
%fact
?. ?=(%metadata-hook-update p.cage.sign) `this
=+ !<(=hook-update:metadata q.cage.sign)
?. ?=(%preview -.hook-update) `this
(flush-blocking title.metadatum.hook-update)
==
::
++ flush-blocking
|= to=cord
:_ this(blocked (~(del by blocked) rid))
%+ turn ~(tap in blocking)
|= [uid=serial:invite =invite:invite]
(~(created inv:cc %groups uid) invite to)
--
::
2021-09-06 06:31:11 +03:00
++ take-invites
?- -.sign
?(%poke-ack %watch-ack) (on-agent:def wire sign)
%kick :_(this (drop safe-watch:invite-store:cc))
2021-09-06 06:31:11 +03:00
::
%fact
?. ?=(%invite-update p.cage.sign) `this
=+ !<(=update:invite q.cage.sign)
?+ -.update `this
::
%accepted
2021-09-06 06:31:11 +03:00
:_ this
~(dismissed inv:cc [term uid]:update)^~
2021-09-06 06:31:11 +03:00
::
%decline
~& decline/uid.update
2021-09-06 06:31:11 +03:00
:_ this
~(dismissed inv:cc [term uid]:update)^~
::
%invite
=* rid resource.invite.update
?+ term.update
:: default
=/ fallback (rap 3 (scot %p entity.rid) '/' name.rid ~)
:_ this
(~(created inv:cc [term uid]:update) invite.update fallback)^~
::
%groups
=. blocked (~(put ju blocked) rid [uid invite]:update)
:_ this
(drop ~(safe-watch preview:cc rid))
::
%graph
:_ this
(~(created inv:cc [term uid]:update) invite.update 'a group chat')^~
==
2021-09-06 06:31:11 +03:00
==
==
--
::
++ on-arvo on-arvo:def
++ on-fail on-fail:def
++ on-leave on-leave:def
--
|_ =bowl:gall
+* io ~(. agentio bowl)
pass pass:io
++ ha
|%
++ pass ~(. ^pass /hark)
++ poke
|=(=action:hark (poke-our:pass %hark-store hark-action+!>(action)))
--
++ invite-store
2021-09-06 06:31:11 +03:00
|%
++ path /updates
++ wire /invites
++ pass ~(. ^pass wire)
++ watch (watch-our:pass %invite-store path)
++ watching (~(has by wex.bowl) [wire our.bowl %invite-store])
++ safe-watch `(unit card)`?:(watching ~ `watch)
--
::
++ preview
|_ rid=resource
++ path preview+(en-path:resource rid)
++ wire groups+(en-path:resource rid)
++ pass ~(. ^pass wire)
++ watching (~(has by wex.bowl) [wire our.bowl %metadata-pull-hook])
++ watch (watch-our:pass %metadata-pull-hook path)
++ safe-watch `(unit card)`?:(watching ~ `watch)
--
2021-09-06 06:31:11 +03:00
::
++ inv
|_ [=term uid=serial:invite]
++ bin [/ place]
++ path /[term]/(scot %uv uid)
++ place `place:hark`[q.byk.bowl path]
++ dismissed
2021-09-06 06:31:11 +03:00
(poke:ha %del-place place)
++ created
|= [=invite:invite to=cord]
2021-09-06 06:31:11 +03:00
=; =body:hark
(poke:ha %add-note bin body)
=, invite
=/ title=@t
(rap 3 'You have been invited to ' to ' by ' ~)
2021-09-06 06:31:11 +03:00
:* ~[text+title ship+ship]
~[text+text]
now.bowl
/
invite+path
2021-09-06 06:31:11 +03:00
==
--
--