Merge pull request #3721 from urbit/la/modernize-invites

invite-store/hook: modernize the code style to match other new apps
This commit is contained in:
L 2020-10-27 19:37:44 -05:00 committed by GitHub
commit 210a9f968c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 477 additions and 438 deletions

View File

@ -10,7 +10,7 @@
:: and trust it to take care of the rest.
::
/- view=chat-view, hook=chat-hook, *group,
*permission-store, *group-store, *invite-store,
*permission-store, *group-store, inv=invite-store,
sole
/+ shoe, default-agent, verb, dbug, store=chat-store,
group-store, grpl=group, resource
@ -27,7 +27,7 @@
+$ state-2
$: %2
grams=(list mail) :: all messages
known=(set [target serial]) :: known message lookup
known=(set [target serial:store]) :: known message lookup
count=@ud :: (lent grams)
bound=(map target glyph) :: bound circle glyphs
binds=(jug glyph target) :: circle glyph lookup
@ -54,7 +54,7 @@
::
+$ state-0
$: grams=(list [[=ship =path] envelope:store]) :: all messages
known=(set [[=ship =path] serial]) :: known message lookup
known=(set [[=ship =path] serial:store]) :: known message lookup
count=@ud :: (lent grams)
bound=(map [=ship =path] glyph) :: bound circle glyphs
binds=(jug glyph [=ship =path]) :: circle glyph lookup
@ -161,7 +161,7 @@
%fact
?+ p.cage.sign ~|([%chat-cli-bad-sub-mark wire p.cage.sign] !!)
%chat-update (diff-chat-update:tc wire !<(update:store q.cage.sign))
%invite-update (handle-invite-update:tc !<(invite-update q.cage.sign))
%invite-update (handle-invite-update:tc !<(update:inv q.cage.sign))
==
==
[cards this]
@ -224,9 +224,9 @@
grams ~ ::NOTE this only impacts historic message lookup in chat-cli
::
known
^- (set [target serial])
^- (set [target serial:store])
%- ~(run in known.u.old)
|= [t=[ship path] s=serial]
|= [t=[ship path] s=serial:store]
[`target`[| t] s]
::
bound
@ -324,7 +324,7 @@
:: +handle-invite-update: get new invites
::
++ handle-invite-update
|= upd=invite-update
|= upd=update:inv
^- (quip card _state)
?+ -.upd [~ state]
%invite [[(show-invite:sh-out invite.upd) ~] state]
@ -722,12 +722,11 @@
%poke
%invite-action
::
!>
^- invite-action
:^ %invite /chat
!> ^- action:inv
:^ %invite %chat
(shax (jam [our-self where] who))
^- invite
[our-self %chat-hook where who '']
^- invite:inv
[our-self %chat-hook (de-path:resource where) who '']
==
:: +set-target: set audience, update prompt
::
@ -865,7 +864,7 @@
|= =letter:store
^- (quip card _state)
~! bowl
=/ =serial (shaf %msg-uid eny.bowl)
=/ =serial:store (shaf %msg-uid eny.bowl)
:_ state
^- (list card)
%+ turn ~(tap in audience)
@ -1132,11 +1131,9 @@
:: +show-invite: print incoming invite notification
::
++ show-invite
|= invite
|= invite:inv
^- card
%- note
%+ weld "invited to: "
~(phat tr (path-to-target path))
(note "invited to: {(scow %p entity.resource)} {(trip name.resource)}")
--
::
:: +tr: render targets

View File

@ -2,7 +2,7 @@
:: mirror chat data from foreign to local based on read permissions
:: allow sending chat messages to foreign paths based on write perms
::
/- *permission-store, *invite-store, *metadata-store,
/- *permission-store, inv=invite-store, *metadata-store,
*permission-hook, *group-store, *permission-group-hook, ::TMP for upgrade
hook=chat-hook,
view=chat-view,
@ -52,7 +52,7 @@
+$ poke
$% [%chat-action action:store]
[%permission-action permission-action]
[%invite-action invite-action]
[%invite-action action:inv]
[%chat-view-action action:view]
==
::
@ -77,7 +77,7 @@
++ on-init
^- (quip card _this)
:_ this(invite-created %.y)
:~ (invite-poke:cc [%create /chat])
:~ (invite-poke:cc [%create %chat])
[%pass /invites %agent [our.bol %invite-store] %watch /invitatory/chat]
watch-groups:cc
==
@ -406,7 +406,7 @@
::
%invite-update
=^ cards state
(fact-invite-update:cc wire !<(invite-update q.cage.sign))
(fact-invite-update:cc wire !<(update:inv q.cage.sign))
[cards this]
::
%group-update
@ -719,15 +719,18 @@
==
::
++ fact-invite-update
|= [wir=wire fact=invite-update]
|= [wir=wire fact=update:inv]
^- (quip card _state)
:_ state
?+ -.fact ~
%accepted
=/ ask-history ?~((chat-scry path.invite.fact) %.y %.n)
=* shp ship.invite.fact
=* app-path path.invite.fact
~[(chat-view-poke [%join shp app-path ask-history])]
=* resource resource.invite.fact
=/ =path [(scot %p entity.resource) name.resource ~]
:_ ~
%- chat-view-poke
:^ %join ship.invite.fact
path
?=(~ (chat-scry path))
==
::
++ fact-group-update
@ -919,9 +922,9 @@
[%pass / %agent [our.bol %chat-view] %poke %chat-view-action !>(act)]
::
++ invite-poke
|= act=invite-action
|= =action:inv
^- card
[%pass / %agent [our.bol %invite-store] %poke %invite-action !>(act)]
[%pass / %agent [our.bol %invite-store] %poke %invite-action !>(action)]
::
++ sec-to-perm
|= [pax=path =kind]
@ -936,9 +939,9 @@
[%mailbox pax]
::
++ invite-scry
|= uid=serial
^- (unit invite)
%^ scry (unit invite)
|= uid=serial:inv
^- (unit invite:inv)
%^ scry (unit invite:inv)
%invite-store
/invite/chat/(scot %uv uid)
::

View File

@ -6,7 +6,7 @@
/- *permission-store,
*permission-hook,
*group,
*invite-store,
inv=invite-store,
*metadata-store,
group-hook,
*permission-group-hook,
@ -407,13 +407,14 @@
^- card
=/ managed=?
!=(ship+app-path group-path)
=/ =invite
=/ =invite:inv
:* our.bol
?:(managed %contact-hook %chat-hook)
?:(managed group-path app-path)
(de-path:resource ?:(managed group-path ship+app-path))
ship ''
==
=/ act=invite-action [%invite ?:(managed /contacts /chat) (shaf %msg-uid eny.bol) invite]
=/ act=action:inv
[%invite ?:(managed %contacts %chat) (shaf %msg-uid eny.bol) invite]
[%pass / %agent [our.bol %invite-hook] %poke %invite-action !>(act)]
::
++ chat-scry

View File

@ -4,7 +4,7 @@
/- group-hook,
*contact-hook,
*contact-view,
*invite-store,
inv=invite-store,
*metadata-hook,
*metadata-store,
*group
@ -44,7 +44,7 @@
++ on-init
^- (quip card _this)
:_ this(invite-created %.y)
:~ (invite-poke:cc [%create /contacts])
:~ (invite-poke:cc [%create %contacts])
[%pass /inv %agent [our.bol %invite-store] %watch /invitatory/contacts]
[%pass /group %agent [our.bol %group-store] %watch /groups]
==
@ -467,20 +467,10 @@
(contact-poke [%delete path])
(contact-poke [%remove path ship])
==
::
++ send-invite-poke
|= [=path =ship]
^- card
=/ =invite
:* our.bol %contact-hook
path ship ''
==
=/ act=invite-action [%invite /contacts (shaf %msg-uid eny.bol) invite]
[%pass / %agent [our.bol %invite-hook] %poke %invite-action !>(act)]
--
::
++ invite-poke
|= act=invite-action
|= act=action:inv
^- card
[%pass / %agent [our.bol %invite-store] %poke %invite-action !>(act)]
::

View File

@ -5,7 +5,7 @@
::
/-
group-hook,
*invite-store,
inv=invite-store,
*contact-hook,
*metadata-store,
*metadata-hook,
@ -161,27 +161,22 @@
%+ turn
~(tap in pending.policy.act)
|= =ship
(send-invite our.bol %contacts path ship '')
(send-invite our.bol %contacts rid ship '')
==
::
%join
=/ =path
(en-path:resource resource.act)
=/ =cage
:- %group-update
!> ^- update:group-store
[%add-members resource.act (sy our.bol ~)]
=/ =wire
[%join-group path]
[%join-group (en-path:resource resource.act)]
[%pass wire %agent [entity.resource.act %group-push-hook] %poke cage]~
::
%invite
=* rid resource.act
=/ =path
(en-path:resource rid)
=/ =group
(need (scry-group:grp rid))
:- (send-invite entity.rid %contacts path ship.act text.act)
=/ =group (need (scry-group:grp rid))
:- (send-invite entity.rid %contacts rid ship.act text.act)
?. ?=(%invite -.policy.group) ~
~[(add-pending rid ship.act)]
::
@ -276,12 +271,12 @@
[%pass / %agent [entity.rid app] %poke cage]
::
++ send-invite
|= =invite
|= =invite:inv
^- card
=/ =cage
:- %invite-action
!> ^- invite-action
[%invite /contacts (shaf %invite-uid eny.bol) invite]
!> ^- action:inv
[%invite %contacts (shaf %invite-uid eny.bol) invite]
[%pass / %agent [recipient.invite %invite-hook] %poke cage]
::
++ contact-poke

View File

@ -1,123 +1,121 @@
:: 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.
::
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
::
++ 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
=/ act=action !<(action vase)
?+ -.act ~
%invites
?. (team:title [our src]:bowl) ~
:: outgoing. we must be inviting other ships. send them each an invite
::
?> (team:title our.bowl src.bowl)
=/ act (json-to-action !<(json vase))
?> ?=(%invite -.act)
[(invite-hook-poke:do recipient.invite.act act)]~
%+ turn ~(tap in recipients.invites.act)
|= recipient=ship
^- card
?< (team:title our.bowl recipient)
%+ invite-hook-poke recipient
:^ %invite term.act uid.act
^- invite
:* ship.invites.act
app.invites.act
resource.invites.act
recipient
text.invites.act
==
::
%invite-action
=/ act=invite-action !<(invite-action vase)
?. ?=(%invite -.act) ~
?: (team:title our.bowl src.bowl)
%invite
?: (team:title [our 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)]~
[(invite-hook-poke 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)]~
?> ?=(^ (invitatory-scry term.act))
?> ?=(~ (invite-scry term.act uid.act))
[(invite-poke term.act act)]~
==
==
::
++ invite-hook-poke
|= [=ship =action]
^- card
:* %pass
/invite-hook
%agent
[ship %invite-hook]
%poke
%invite-action
!>(action)
==
::
++ 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
++ invite-poke
|= [=term =action]
^- card
:* %pass
/[term]
%agent
[our.bowl %invite-store]
%poke
%invite-action
!>(action)
==
::
++ invitatory-scry
|= =term
.^ (unit invitatory)
%gx
%+ weld
/(scot %p our.bowl)/invite-store/(scot %da now.bowl)/invitatory
/[term]/noun
==
::
++ invite-scry
|= [=term uid=serial]
.^ (unit invite)
%gx
%+ weld
/(scot %p our.bowl)/invite-store/(scot %da now.bowl)/invite
/[term]/(scot %uv uid)/noun
==
--
::
|_ =bowl:gall
::
++ invite-hook-poke
|= [=ship action=invite-action]
^- card
:* %pass
/invite-hook
%agent
[ship %invite-hook]
%poke
%invite-action
!>(action)
==
::
++ 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
==
.^((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
--

View File

@ -1,184 +1,209 @@
:: invite-store [landscape]
/+ *invite-json, default-agent, dbug
/- store=invite-store
/+ res=resource, default-agent, dbug
|%
+$ card card:agent:gall
::
+$ versioned-state
$% state-zero
$% state-0
state-1
==
::
+$ state-zero
$: %0
=invites
+$ invitatory-0 (map serial:store invite-0)
+$ invite-0
$: =ship :: ship to subscribe to upon accepting invite
app=@tas :: app to subscribe to upon accepting invite
=path :: path to subscribe to upon accepting invite
recipient=ship :: recipient to receive invite
text=cord :: text to describe the invite
==
::
+$ state-0 [%0 invites=(map path invitatory-0)]
+$ state-1 [%1 =invites:store]
--
::
=| state-zero
=| state-1
=* state -
%- agent:dbug
^- agent:gall
=<
|_ bol=bowl:gall
+* this .
inv-core +>
ic ~(. inv-core bol)
def ~(. (default-agent this %|) bol)
++ on-init on-init:def
++ on-save !>(state)
++ on-load
|= old=vase
`this(state !<(state-zero old))
::
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
::
++ on-init
^- (quip card _this)
:- ~
%_ this
invites.state
%- ~(gas by *invites:store)
[%graph *invitatory:store]~
==
::
++ on-save !>(state)
++ on-load
|= old-vase=vase
=/ old !<(versioned-state old-vase)
?: ?=(%1 -.old)
`this(state old)
:- =- [%pass / %agent [our.bowl %invite-store] %poke %invite-action !>(-)]~
!> ^- action:store
[%create %graph]
%= this
state
:- %1
%- ~(gas by *invites:store)
%+ murn ~(tap by invites.old)
|= [=path =invitatory-0]
^- (unit [term invitatory:store])
?. ?=([@ ~] path) ~
:- ~
:- i.path
%- ~(gas by *invitatory:store)
%+ murn ~(tap by invitatory-0)
|= [=serial:store =invite-0]
^- (unit [serial:store invite:store])
=/ resource=(unit resource:res) (de-path-soft:res path.invite-0)
?~ resource ~
:- ~
:- serial
^- invite:store
:* ship.invite-0
app.invite-0
u.resource
recipient.invite-0
text.invite-0
==
==
::
++ on-agent on-agent:def
++ on-arvo on-arvo:def
++ on-leave on-leave:def
++ on-fail on-fail:def
::
++ on-watch
|= =path
^- (quip card _this)
?> (team:title our.bowl src.bowl)
=/ cards=(list card)
?+ path (on-watch:def path)
[%all ~] [%give %fact ~ %invite-update !>([%initial invites])]~
[%updates ~] ~
[%invitatory @ ~]
=/ inv=invitatory:store (~(got by invites) i.t.path)
[%give %fact ~ %invite-update !>([%invitatory inv])]~
==
[cards this]
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
|^
?> (team:title our.bowl src.bowl)
=^ cards state
?+ mark (on-poke:def mark vase)
%invite-action (poke-invite-action !<(action:store vase))
==
[cards this]
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
?> (team:title our.bol src.bol)
=^ cards state
?+ mark (on-poke:def mark vase)
%json (poke-invite-action:ic (json-to-action !<(json vase)))
%invite-action (poke-invite-action:ic !<(invite-action vase))
==
[cards this]
::
++ on-watch
|= =path
^- (quip card _this)
=/ cards=(list card)
?+ path (on-watch:def path)
[%all ~] [%give %fact ~ %invite-update !>([%initial invites])]~
[%updates ~] ~
[%invitatory *]
=/ inv=invitatory (~(got by invites) t.path)
[%give %fact ~ %invite-update !>([%invitatory inv])]~
==
[cards this]
::
++ on-leave on-leave:def
++ on-peek
|= =path
^- (unit (unit cage))
?+ path (on-peek:def path)
[%x %all ~] (peek-x-all:ic t.t.path)
[%x %invitatory *] (peek-x-invitatory:ic t.t.path)
[%x %invite *] (peek-x-invite:ic t.t.path)
++ poke-invite-action
|= =action:store
^- (quip card _state)
?- -.action
%create (handle-create +.action)
%delete (handle-delete +.action)
%invite (handle-invite +.action)
%accept (handle-accept +.action)
%decline (handle-decline +.action)
%invites ~|('only send this to %invite-hook' !!)
==
::
++ on-agent on-agent:def
++ on-arvo on-arvo:def
++ on-fail on-fail:def
++ handle-create
|= =term
^- (quip card _state)
?: (~(has by invites) term)
[~ state]
:- (send-diff term [%create term])
state(invites (~(put by invites) term *invitatory:store))
::
++ handle-delete
|= =term
^- (quip card _state)
?. (~(has by invites) term)
[~ state]
:- (send-diff term [%delete term])
state(invites (~(del by invites) term))
::
++ handle-invite
|= [=term =serial:store =invite:store]
^- (quip card _state)
?. (~(has by invites) term)
[~ state]
=/ container (~(got by invites) term)
=. serial (sham eny.bowl)
=. container (~(put by container) serial invite)
:- (send-diff term [%invite term serial invite])
state(invites (~(put by invites) term container))
::
++ handle-accept
|= [=term =serial:store]
^- (quip card _state)
?. (~(has by invites) term)
[~ state]
=/ container (~(got by invites) term)
=/ invite (~(get by container) serial)
?~ invite
[~ state]
=. container (~(del by container) serial)
:- (send-diff term [%accepted term serial u.invite])
state(invites (~(put by invites) term container))
::
++ handle-decline
|= [=term =serial:store]
^- (quip card _state)
?. (~(has by invites) term)
[~ state]
=/ container (~(got by invites) term)
=/ invite (~(get by container) serial)
?~ invite
[~ state]
=. container (~(del by container) serial)
:- (send-diff term [%decline term serial])
state(invites (~(put by invites) term container))
::
++ update-subscribers
|= [=path =update:store]
^- card
[%give %fact ~[path] %invite-update !>(update)]
::
++ send-diff
|= [=term =update:store]
^- (list card)
:~ (update-subscribers /all update)
(update-subscribers /updates update)
(update-subscribers /invitatory/[term] update)
==
--
::
|_ bol=bowl:gall
::
++ peek-x-all
|= pax=path
++ on-peek
|= =path
^- (unit (unit cage))
[~ ~ %noun !>(invites)]
::
++ peek-x-invitatory
|= pax=path
^- (unit (unit cage))
?~ pax
~
=/ invitatory=(unit invitatory) (~(get by invites) pax)
[~ ~ %noun !>(invitatory)]
::
++ peek-x-invite
|= pax=path
^- (unit (unit cage))
:: /:path/:uid
=/ pas (flop pax)
?~ pas
~
=/ uid=serial (slav %uv i.pas)
=. pax (scag (dec (lent pax)) `(list @ta)`pax)
=/ invitatory=(unit invitatory) (~(get by invites) pax)
?~ invitatory
~
=/ invite=(unit invite) (~(get by u.invitatory) uid)
[~ ~ %noun !>(invite)]
::
++ poke-invite-action
|= action=invite-action
^- (quip card _state)
?> (team:title our.bol src.bol)
?- -.action
%create (handle-create action)
%delete (handle-delete action)
%invite (handle-invite action)
%accept (handle-accept action)
%decline (handle-decline action)
?+ path (on-peek:def path)
[%x %all ~]
``noun+!>(invites)
::
[%x %invitatory @ ~]
:^ ~ ~ %noun
!> ^- (unit invitatory:store)
(~(get by invites) i.t.t.path)
::
[%x %invite @ @ ~]
=* term i.t.t.path
=/ =serial:store (slav %uv i.t.t.t.path)
?. (~(has by invites) term)
~
=/ =invitatory:store (~(got by invites) term)
:^ ~ ~ %noun
!> ^- (unit invite:store)
(~(get by invitatory) serial)
==
::
++ handle-create
|= act=invite-action
^- (quip card _state)
?> ?=(%create -.act)
?: (~(has by invites) path.act)
[~ state]
:- (send-diff path.act act)
state(invites (~(put by invites) path.act *invitatory))
::
++ handle-delete
|= act=invite-action
^- (quip card _state)
?> ?=(%delete -.act)
?. (~(has by invites) path.act)
[~ state]
:- (send-diff path.act act)
state(invites (~(del by invites) path.act))
::
++ handle-invite
|= act=invite-action
^- (quip card _state)
?> ?=(%invite -.act)
?. (~(has by invites) path.act)
[~ state]
=/ container (~(got by invites) path.act)
=. uid.act (sham eny.bol)
=. container (~(put by container) uid.act invite.act)
:- (send-diff path.act act)
state(invites (~(put by invites) path.act container))
::
++ handle-accept
|= act=invite-action
^- (quip card _state)
?> ?=(%accept -.act)
?. (~(has by invites) path.act)
[~ state]
=/ container (~(got by invites) path.act)
=/ invite (~(get by container) uid.act)
?~ invite
[~ state]
=. container (~(del by container) uid.act)
:- (send-diff path.act [%accepted path.act uid.act u.invite])
state(invites (~(put by invites) path.act container))
::
++ handle-decline
|= act=invite-action
^- (quip card _state)
?> ?=(%decline -.act)
?. (~(has by invites) path.act)
[~ state]
=/ container (~(got by invites) path.act)
=/ invite (~(get by container) uid.act)
?~ invite
[~ state]
=. container (~(del by container) uid.act)
:- (send-diff path.act act)
state(invites (~(put by invites) path.act container))
::
++ update-subscribers
|= [pax=path upd=invite-update]
^- card
[%give %fact ~[pax] %invite-update !>(upd)]
::
++ send-diff
|= [pax=path upd=invite-update]
^- (list card)
:~ (update-subscribers /all upd)
(update-subscribers /updates upd)
(update-subscribers [%invitatory pax] upd)
==
::
--

View File

@ -8,7 +8,7 @@
/- *permission-hook
/- *permission-group-hook
/- *permission-store
/- *invite-store
/- inv=invite-store
/- *metadata-store
/- *metadata-hook
/- contact-view
@ -91,7 +91,7 @@
:_ this
:~ [%pass /view-bind %arvo %e %connect [~ /'publish-view'] %publish]
[%pass /read/paths %arvo %c %warp our.bol q.byk.bol `rav]
(invite-poke:main [%create /publish])
(invite-poke:main [%create %publish])
:* %pass /invites %agent [our.bol %invite-store] %watch
/invitatory/publish
==
@ -122,7 +122,7 @@
:* %pass /permissions %agent [our.bol %permission-store] %watch
/updates
==
(invite-poke:main [%create /publish])
(invite-poke:main [%create %publish])
:* %pass /invites %agent [our.bol %invite-store] %watch
/invitatory/publish
==
@ -136,10 +136,10 @@
=+ ^- [kick-cards=(list card) old-subs=(jug @tas @p)] kick-subs
=/ inv-scry-pax
/(scot %p our.bol)/invite-store/(scot %da now.bol)/invitatory/publish/noun
=/ inv=(unit invitatory) .^((unit invitatory) %gx inv-scry-pax)
=/ invi=(unit invitatory:inv) .^((unit invitatory:inv) %gx inv-scry-pax)
=| new-state=state-two
=? tile-num.new-state ?=(^ inv)
~(wyt by u.inv)
=? tile-num.new-state ?=(^ invi)
~(wyt by u.invi)
%= $
old-state [%& %2 new-state]
::
@ -312,12 +312,12 @@
|= who=@p
^- card
=/ uid (sham %publish who book eny.bol)
=/ inv=invite
:* our.bol %publish /notebook/[book] who
=/ =invite:inv
:* our.bol %publish [our.bol book] who
(crip "invite for notebook {<our.bol>}/{(trip book)}")
==
=/ act=invite-action [%invite /publish uid inv]
[%pass /invite %agent [who %invite-hook] %poke %invite-action !>(act)]
=/ =action:inv [%invite %publish uid invite]
[%pass /invite %agent [who %invite-hook] %poke %invite-action !>(action)]
::
++ move-files
|= old-subs=(jug @tas @p)
@ -545,7 +545,7 @@
::
[%invites ~]
=^ cards state
(handle-invite-update:main !<(invite-update q.cage.sin))
(handle-invite-update:main !<(update:inv q.cage.sin))
[cards this]
::
[%collection *]
@ -1042,39 +1042,29 @@
?: ?|(?=(%remove-members -.update) (is-managed-path:grup path))
~
=/ uid (sham %publish who u.book eny.bol)
=/ inv=invite
:* our.bol %publish /notebook/[u.book] who
=/ =invite:inv
:* our.bol %publish [our.bol u.book] who
(crip "invite for notebook {<our.bol>}/{(trip u.book)}")
==
=/ act=invite-action [%invite /publish uid inv]
=/ act=action:inv [%invite %publish uid invite]
[%pass / %agent [our.bol %invite-hook] %poke %invite-action !>(act)]~
::
++ handle-invite-update
|= upd=invite-update
|= upd=update:inv
^- (quip card _state)
?+ -.upd
[~ state]
::
%delete
[~ state]
::
%invite
[~ state]
::
%decline
[~ state]
?+ -.upd [~ state]
%delete [~ state]
%invite [~ state]
%decline [~ state]
::
%accepted
?> ?=([@ @ *] path.invite.upd)
=/ book i.t.path.invite.upd
=* rid resource.invite.upd
=/ group
(group-from-book notebook+book^~)
(group-from-book notebook+name.rid^~)
?^ group
(subscribe-notebook ship.invite.upd book)
=/ rid=resource
(de-path:resource ship+path.invite.upd)
(subscribe-notebook ship.invite.upd name.rid)
=/ join-wire=wire
/join-group/[(scot %p ship.invite.upd)]/[book]
/join-group/[(scot %p ship.invite.upd)]/[name.rid]
=/ =cage
:- %group-update
!> ^- action:group-store
@ -1232,7 +1222,7 @@
==
::
++ invite-poke
|= act=invite-action
|= act=action:inv
^- card
[%pass / %agent [our.bol %invite-store] %poke %invite-action !>(act)]
::
@ -1254,11 +1244,11 @@
%+ turn ~(tap in invitees)
|= who=ship
=/ uid (sham %publish who book eny.bol)
=/ inv=invite
:* our.bol %publish /(scot %p our.bol)/[book] who
=/ =invite:inv
:* our.bol %publish [our.bol book] who
(crip "invite for notebook {<our.bol>}/{(trip book)}")
==
=/ act=invite-action [%invite /publish uid inv]
=/ act=action:inv [%invite %publish uid invite]
[%pass / %agent [our.bol %invite-hook] %poke %invite-action !>(act)]
::
++ make-groups
@ -1941,13 +1931,14 @@
%+ turn
~(tap in ships)
|= =ship
=/ =invite
=/ =invite:inv
:* our.bol
%contact-hook
group-path
rid
ship ''
==
=/ act=invite-action [%invite /contacts (shaf %msg-uid eny.bol) invite]
=/ act=action:inv
[%invite %contacts (shaf %msg-uid eny.bol) invite]
[%pass / %agent [our.bol %invite-hook] %poke %invite-action !>(act)]
==
==

View File

@ -1,4 +1,5 @@
/- *invite-store
/+ resource
|%
++ slan |=(mod/@tas |=(txt/@ta (need (slaw mod txt))))
::
@ -12,9 +13,9 @@
^- json
%- pairs:enjs:format
%+ turn ~(tap by inv)
|= [=path =invitatory]
|= [=term =invitatory]
^- [cord json]
[(spat path) (invitatory-to-json invitatory)]
[term (invitatory-to-json invitatory)]
::
++ invitatory-to-json
|= =invitatory
@ -33,13 +34,13 @@
%- pairs
:~ [%ship (ship ship.invite)]
[%app [%s app.invite]]
[%path (path path.invite)]
[%resource (enjs:resource resource.invite)]
[%recipient (ship recipient.invite)]
[%text [%s text.invite]]
==
::
++ update-to-json
|= upd=invite-update
|= upd=update
=, enjs:format
^- json
%+ frond %invite-update
@ -50,15 +51,15 @@
[%initial (invites-to-json invites.upd)]
?: =(%create -.upd)
?> ?=(%create -.upd)
[%create (pairs [%path (path path.upd)]~)]
[%create (pairs [%term s+term.upd]~)]
?: =(%delete -.upd)
?> ?=(%delete -.upd)
[%delete (pairs [%path (path path.upd)]~)]
[%delete (pairs [%term s+term.upd]~)]
?: =(%accepted -.upd)
?> ?=(%accepted -.upd)
:- %accepted
%- pairs
:~ [%path (path path.upd)]
:~ [%term s+term.upd]
[%uid s+(scot %uv uid.upd)]
[%invite (invite-to-json invite.upd)]
==
@ -66,14 +67,14 @@
?> ?=(%decline -.upd)
:- %decline
%- pairs
:~ [%path (path path.upd)]
:~ [%term s+term.upd]
[%uid s+(scot %uv uid.upd)]
==
?: =(%invite -.upd)
?> ?=(%invite -.upd)
:- %invite
%- pairs
:~ [%path (path path.upd)]
:~ [%term s+term.upd]
[%uid s+(scot %uv uid.upd)]
[%invite (invite-to-json invite.upd)]
==
@ -88,53 +89,45 @@
::
++ json-to-action
|= jon=json
^- invite-action
^- action
=, dejs:format
=< (parse-json jon)
|%
++ parse-json
%- of
:~ [%create create]
[%delete delete]
:~ [%create so]
[%delete so]
[%invite invite]
[%accept accept]
[%decline decline]
==
::
++ create
(ot [%path pa]~)
::
++ delete
(ot [%path pa]~)
::
++ invite
%- ot
:~ [%path pa]
:~ [%term so]
[%uid seri]
[%invite invi]
==
::
++ accept
%- ot
:~ [%path pa]
:~ [%term so]
[%uid seri]
==
::
++ decline
%- ot
:~ [%path pa]
:~ [%term so]
[%uid seri]
==
::
++ invi
%- ot
:~ [%ship (su ;~(pfix sig fed:ag))]
[%app (se %tas)]
[%path pa]
[%app so]
[%resource dejs:resource]
[%recipient (su ;~(pfix sig fed:ag))]
[%text so]
==
--
--

View File

@ -1,6 +1,6 @@
/+ *invite-json
=, dejs:format
|_ act=invite-action
|_ act=action
++ grad %noun
++ grow
|%
@ -8,7 +8,7 @@
--
++ grab
|%
++ noun invite-action
++ noun action
++ json
|= jon=^json
(json-to-action jon)

View File

@ -1,15 +1,15 @@
/- store=invite-store
/+ *invite-json
|_ upd=invite-update
|_ =update:store
++ grad %noun
++ grow
|%
++ noun upd
++ json (update-to-json upd)
++ noun update
++ json (update-to-json update)
--
::
++ grab
|%
++ noun invite-update
++ noun update:store
--
::
--

View File

@ -1,45 +1,49 @@
/- *resource
|%
++ serial @uvH
::
+$ invite
$: =ship :: ship to subscribe to upon accepting invite
app=@tas :: app to subscribe to upon accepting invite
=path :: path to subscribe to upon accepting invite
=resource :: resource to subscribe to upon accepting invite
recipient=ship :: recipient to receive invite
text=cord :: text to describe the invite
==
::
:: +invites: each application using invites creates its own path that
+$ multi-invite
$: =ship :: ship to subscribe to upon accepting invite
app=@tas :: app to subscribe to upon accepting invite
=resource :: resource to subscribe to upon accepting invite
recipients=(set ship) :: recipient to receive invite
text=cord :: text to describe the invite
==
::
:: +invites: each application using invites creates its own resource that
:: contains a map of serial to invite. this allows it to only receive
:: invites that it is concerned with
::
+$ invites (map path invitatory) :: main data structure
+$ invites (map term invitatory) :: main data structure
::
+$ invitatory (map serial invite) :: containing or conveying an invitation
::
::
+$ invite-base
$% [%create =path] :: create a path
[%delete =path] :: delete a path
[%invite =path uid=serial =invite] :: receive an invite at path/uid
[%decline =path uid=serial] :: decline an invite at path/uid
$% [%create =term] :: create a resource
[%delete =term] :: delete a resource
[%invite =term uid=serial =invite] :: receive an invite at term/uid
[%decline =term uid=serial] :: decline an invite at term/uid
==
::
+$ invite-action
+$ action
$% invite-base
[%accept =path uid=serial] :: accept an invite at path/uid
[%accept =term uid=serial] :: accept an invite at term/uid
[%invites =term uid=serial invites=multi-invite]
==
::
+$ invite-update
+$ update
$% invite-base
[%initial =invites]
[%invitatory =invitatory] :: receive invitatory
[%accepted =path uid=serial =invite] :: an invite has been accepted
==
::
+$ invite-diff
$% [%invite-initial invites]
[%invite-update invite-update]
[%invitatory =invitatory] :: receive invitatory
[%accepted =term uid=serial =invite] :: an invite has been accepted
==
--

View File

@ -1,4 +1,9 @@
/- spider, graph=graph-store, *metadata-store, *group, group-store
/- spider,
graph=graph-store,
*metadata-store,
*group,
group-store,
inv=invite-store
/+ strandio, resource, graph-view
=>
|%
@ -27,6 +32,7 @@
=+ !<([=action:graph-view ~] arg)
?> ?=(%create -.action)
;< =bowl:spider bind:m get-bowl:strandio
::
:: Add graph to graph-store
::
?. =(our.bowl entity.rid.action)
@ -37,12 +43,14 @@
(poke-our %graph-store graph-update+!>(update))
;< ~ bind:m
(poke-our %graph-push-hook %push-hook-action !>([%add rid.action]))
::
:: Add group, if graph is unmanaged
::
;< group=resource bind:m
(handle-group rid.action associated.action)
=/ group-path=path
(en-path:resource group)
::
:: Setup metadata
::
=/ =metadata
@ -53,9 +61,30 @@
creator our.bowl
module module.action
==
=/ act=metadata-action
=/ =metadata-action
[%add group-path graph+(en-path:resource rid.action) metadata]
;< ~ bind:m (poke-our %metadata-hook %metadata-action !>(act))
;< ~ bind:m
(poke-our %metadata-hook %metadata-action !>(metadata-action))
;< ~ bind:m
(poke-our %metadata-hook %metadata-hook-action !>([%add-owned group-path]))
(pure:m !>(~))
::
:: Send invites
::
?: ?=(%group -.associated)
(pure:m !>(~))
?- -.policy.associated.action
%group (pure:m !>(~))
%invite
=/ inv-action=action:inv
:^ %invites %graph (shaf %graph-uid eny.bowl)
^- multi-invite:inv
:* our.bowl
%graph-push-hook
rid.action
pending.policy.associated.action
description.action
==
;< ~ bind:m
(poke-our %invite-hook %invite-action !>(inv-action))
(pure:m !>(~))
==

View File

@ -3,25 +3,25 @@ import { StoreState } from "../store/type";
import { Serial, Path } from "~/types/noun";
export default class InviteApi extends BaseApi<StoreState> {
accept(app: Path, uid: Serial) {
accept(app: string, uid: Serial) {
return this.inviteAction({
accept: {
path: app,
term: app,
uid
}
});
}
decline(app: Path, uid: Serial) {
decline(app: string, uid: Serial) {
return this.inviteAction({
decline: {
path: app,
term: app,
uid
}
});
}
private inviteAction(action) {
return this.action('invite-store', 'json', action);
return this.action('invite-store', 'invite-action', action);
}
}

View File

@ -29,35 +29,35 @@ export default class InviteReducer<S extends InviteState> {
create(json: InviteUpdate, state: S) {
const data = _.get(json, 'create', false);
if (data) {
state.invites[data.path] = {};
state.invites[data] = {};
}
}
delete(json: InviteUpdate, state: S) {
const data = _.get(json, 'delete', false);
if (data) {
delete state.invites[data.path];
delete state.invites[data];
}
}
invite(json: InviteUpdate, state: S) {
const data = _.get(json, 'invite', false);
if (data) {
state.invites[data.path][data.uid] = data.invite;
state.invites[data.term][data.uid] = data.invite;
}
}
accepted(json: InviteUpdate, state: S) {
const data = _.get(json, 'accepted', false);
if (data) {
delete state.invites[data.path][data.uid];
delete state.invites[data.term][data.uid];
}
}
decline(json: InviteUpdate, state: S) {
const data = _.get(json, 'decline', false);
if (data) {
delete state.invites[data.path][data.uid];
delete state.invites[data.term][data.uid];
}
}
}

View File

@ -17,7 +17,7 @@ const sortGroupsAlph = (a: Association, b: Association) =>
export default function Groups(props: GroupsProps & Parameters<typeof Box>[0]) {
const { associations, invites, api, ...boxProps } = props;
const incomingGroups = Object.values(invites?.['/contacts'] || {});
const incomingGroups = Object.values(invites?.['contacts'] || {});
const getKeyByValue = (object, value) => {
return Object.keys(object).find(key => object[key] === value);
}
@ -26,10 +26,12 @@ export default function Groups(props: GroupsProps & Parameters<typeof Box>[0]) {
.sort(sortGroupsAlph);
const acceptInvite = (invite) => {
const [, , ship, name] = invite.path.split('/');
const resource = { ship, name };
const resource = {
ship: `~${invite.resource.ship}`,
name: invite.resource.name
};
return api.contacts.join(resource).then(() => {
api.invite.accept('/contacts', getKeyByValue(invites['/contacts'], invite));
api.invite.accept('contacts', getKeyByValue(invites['contacts'], invite));
});
};
@ -54,10 +56,16 @@ export default function Groups(props: GroupsProps & Parameters<typeof Box>[0]) {
borderRadius='2'
borderColor='lightGray'
p='2'
fontSize='0'
>
fontSize='0'>
<Text display='block' pb='2' gray>You have been invited to:</Text>
<Text display='inline-block' overflow='hidden' maxWidth='100%' style={{ textOverflow: 'ellipsis', whiteSpace: 'pre' }} title={invite.path.slice(6)}>{invite.path.slice(6)}</Text>
<Text
display='inline-block'
overflow='hidden'
maxWidth='100%'
style={{ textOverflow: 'ellipsis', whiteSpace: 'pre' }}
title={`~${invite.resource.ship}/${invite.resource.name}`}>
{`~${invite.resource.ship}/${invite.resource.name}`}
</Text>
<Box pt='5'>
<Text
onClick={() => acceptInvite(invite)}
@ -68,7 +76,12 @@ export default function Groups(props: GroupsProps & Parameters<typeof Box>[0]) {
</Text>
<Text
color='red'
onClick={() => api.invite.decline('/contacts', getKeyByValue(invites['/contacts'], invite))}
onClick={() =>
api.invite.decline(
'contacts',
getKeyByValue(invites['contacts'], invite)
)
}
cursor='pointer'>
Reject
</Text>

View File

@ -11,7 +11,7 @@ export class SidebarInvite extends Component<{invite: Invite, onAccept: Function
<Box width='100%' verticalAlign='middle'>
<Text display='block' pb='2' gray>You have been invited to:</Text>
<Text display='inline-block'>
{props.invite.path.substr(1)}
{`~${props.invite.resource.ship}/${props.invite.resource.name}`}
</Text>
</Box>
<Row>
@ -39,4 +39,4 @@ export class SidebarInvite extends Component<{invite: Invite, onAccept: Function
}
}
export default SidebarInvite;
export default SidebarInvite;