From b43a5f5534ae469235e24263d731825bd669e641 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Thu, 15 Oct 2020 10:46:12 -0500 Subject: [PATCH] invite-hook: modernized the style and removed inline %json conversion --- pkg/arvo/app/invite-hook.hoon | 188 +++++++++++++++------------------- 1 file changed, 85 insertions(+), 103 deletions(-) diff --git a/pkg/arvo/app/invite-hook.hoon b/pkg/arvo/app/invite-hook.hoon index 0e7b93d97..e27c697d6 100644 --- a/pkg/arvo/app/invite-hook.hoon +++ b/pkg/arvo/app/invite-hook.hoon @@ -1,123 +1,105 @@ -:: invite-hook [landscape]: +:: invite-hook [landscape]: receive invites from any source :: -:: receive invites from any source +:: only handles %invite actions: +:: - can be poked by the host team to send an invite out to someone. +:: - can be poked by foreign ships to send an invite to us. :: -:: only handles %invite actions. accepts json, but only from the host team. -:: can be poked by the host team to send an invite out to someone. -:: can be poked by foreign ships to send an invite to us. -:: -/+ *invite-json, default-agent, verb, dbug +/- *invite-store +/+ default-agent, dbug :: |% +$ state-0 [%0 ~] -:: +$ card card:agent:gall -- :: =| state-0 =* state - -:: -%+ verb | %- agent:dbug ^- agent:gall -=< - |_ =bowl:gall - +* this . - do ~(. +> bowl) - def ~(. (default-agent this %|) bowl) - :: - ++ on-init - ^- (quip card _this) - [~ this] - :: - ++ on-save !>(state) - ++ on-load - |= old=vase - ^- (quip card _this) - [~ this(state !<(state-0 old))] - :: - ++ on-poke - |= [=mark =vase] - ^- (quip card _this) - :_ this - ?+ mark (on-poke:def mark vase) - %json - :: only accept json from ourselves. - :: - ?> (team:title our.bowl src.bowl) - =/ act (json-to-action !<(json vase)) - ?> ?=(%invite -.act) - [(invite-hook-poke:do recipient.invite.act act)]~ - :: - %invite-action - =/ act=invite-action !<(invite-action vase) - ?. ?=(%invite -.act) ~ - ?: (team:title our.bowl src.bowl) - :: outgoing. we must be inviting another ship. send them the invite. - :: - ?< (team:title our.bowl recipient.invite.act) - [(invite-hook-poke:do recipient.invite.act act)]~ - :: else incoming. ensure invitatory exists and invite is not a duplicate. - :: - ?> ?=(^ (invitatory-scry:do path.act)) - ?> ?=(~ (invite-scry:do path.act uid.act)) - [(invite-poke:do path.act act)]~ - == - :: - ++ on-peek on-peek:def - ++ on-watch on-watch:def - ++ on-leave on-leave:def - ++ on-agent on-agent:def - ++ on-arvo on-arvo:def - ++ on-fail on-fail:def - -- :: |_ =bowl:gall ++* this . + def ~(. (default-agent this %|) bowl) :: -++ invite-hook-poke - |= [=ship action=invite-action] - ^- card - :* %pass - /invite-hook - %agent - [ship %invite-hook] - %poke +++ on-init [~ this] +++ on-save !>(state) +++ on-load + |= old=vase + ^- (quip card _this) + [~ this(state !<(state-0 old))] +:: +++ on-poke + |= [=mark =vase] + ^- (quip card _this) + |^ + :_ this + ?+ mark (on-poke:def mark vase) %invite-action - !>(action) + =/ act=invite-action !<(invite-action vase) + ?. ?=(%invite -.act) ~ + ?: (team:title our.bowl src.bowl) + :: outgoing. we must be inviting another ship. send them the invite. + :: + ?< (team:title our.bowl recipient.invite.act) + [(invite-hook-poke recipient.invite.act act)]~ + :: else incoming. ensure invitatory exists and invite is not a duplicate. + :: + ?> ?=(^ (invitatory-scry path.act)) + ?> ?=(~ (invite-scry path.act uid.act)) + [(invite-poke path.act act)]~ == -:: -++ invite-poke - |= [=path action=invite-action] - ^- card - :* %pass - path - %agent - [our.bowl %invite-store] - %poke - %invite-action - !>(action) - == -:: -++ invitatory-scry - |= pax=path - ^- (unit invitatory) - =. pax - ;: weld - /(scot %p our.bowl)/invite-store/(scot %da now.bowl)/invitatory - pax - /noun + :: + ++ invite-hook-poke + |= [=ship action=invite-action] + ^- card + :* %pass + /invite-hook + %agent + [ship %invite-hook] + %poke + %invite-action + !>(action) == - .^((unit invitatory) %gx pax) -:: -++ invite-scry - |= [pax=path uid=serial] - ^- (unit invite) - =. pax - ;: weld - /(scot %p our.bowl)/invite-store/(scot %da now.bowl)/invite - pax - /(scot %uv uid)/noun + :: + ++ invite-poke + |= [=path action=invite-action] + ^- card + :* %pass + path + %agent + [our.bowl %invite-store] + %poke + %invite-action + !>(action) == - .^((unit invite) %gx pax) + :: + ++ invitatory-scry + |= pax=path + ^- (unit invitatory) + =. pax + ;: weld + /(scot %p our.bowl)/invite-store/(scot %da now.bowl)/invitatory + pax + /noun + == + .^((unit invitatory) %gx pax) + :: + ++ invite-scry + |= [pax=path uid=serial] + ^- (unit invite) + =. pax + ;: weld + /(scot %p our.bowl)/invite-store/(scot %da now.bowl)/invite + pax + /(scot %uv uid)/noun + == + .^((unit invite) %gx pax) + -- +:: +++ on-peek on-peek:def +++ on-watch on-watch:def +++ on-leave on-leave:def +++ on-agent on-agent:def +++ on-arvo on-arvo:def +++ on-fail on-fail:def -- -