app: added invite app and mark converters to JSON

This commit is contained in:
Logan Allen 2019-10-31 11:38:23 -07:00
parent f30e1d9993
commit 656f264f96
9 changed files with 509 additions and 0 deletions

View File

@ -0,0 +1,61 @@
:: invite-hook: receive invites from any source
::
/+ *invite-json
|%
+$ move [bone [%poke wire dock [%invite-action invite-action]]]
--
::
|_ [bol=bowl:gall ~]
::
++ this .
::
++ poke-json
|= =json
^- (quip move _this)
?> (team:title our.bol src.bol)
=/ act (json-to-action json)
?> ?=(%invite -.act)
:_ this
[(invite-hook-poke recipient.invite.act act)]~
::
++ poke-invite-action
|= act=invite-action
^- (quip move _this)
:_ this
?+ -.act
~
::
%invite
?: (team:title our.bol src.bol)
?> !(team:title our.bol ship.invite.act)
[(invite-hook-poke recipient.invite.act act)]~
?~ (invitatory-scry path.act) ~
?^ (invite-scry uid.act path.act) ~
[(invite-poke path.act act)]~
==
::
++ invite-hook-poke
|= [=ship action=invite-action]
^- move
[ost.bol %poke /invite-hook [ship %invite-hook] [%invite-action action]]
::
++ invite-poke
|= [pax=path action=invite-action]
^- move
[ost.bol %poke pax [our.bol %invite-store] [%invite-action action]]
::
++ invitatory-scry
|= pax=path
^- (unit invitatory)
=. pax
;:(weld /=invite-store/(scot %da now.bol)/invitatory pax /noun)
.^((unit invitatory) %gx pax)
::
++ invite-scry
|= [uid=serial pax=path]
^- (unit invite)
=. pax
;:(weld /=invite-store/(scot %da now.bol)/invite/(scot %uv uid) pax /noun)
.^((unit invite) %gx pax)
--

View File

@ -0,0 +1,186 @@
/+ *invite-json
|%
+$ move [bone card]
::
+$ card
$% [%diff diff]
[%quit ~]
==
::
+$ state
$% [%0 state-zero]
==
::
+$ state-zero
$: =invites
==
::
+$ diff
$% [%invite-initial invites]
[%invite-update invite-update]
==
--
::
|_ [bol=bowl:gall state]
::
++ this .
::
++ prep
|= old=(unit state)
^- (quip move _this)
?~ old
[~ this]
[~ this(+<+ u.old)]
::
++ peek-x-all
|= pax=path
^- (unit (unit [%noun (map path invitatory)]))
[~ ~ %noun invites]
::
++ peek-x-invitatory
|= pax=path
^- (unit (unit [%noun (unit invitatory)]))
?~ pax
~
=/ invitatory=(unit invitatory) (~(get by invites) pax)
[~ ~ %noun invitatory]
::
++ peek-x-invite
|= pax=path
^- (unit (unit [%noun (unit invite)]))
?~ pax
~
=/ invitatory=(unit invitatory) (~(get by invites) t.pax)
?~ invitatory
~
=/ uid=serial (slav %uv i.pax)
=/ invite=(unit invite) (~(get by u.invitatory) uid)
[~ ~ %noun invite]
::
++ peer-all
|= pax=path
^- (quip move _this)
?> (team:title our.bol src.bol)
:: send all updates from now on
:_ this
[ost.bol %diff %invite-initial invites]~
::
++ peer-updates
|= pax=path
^- (quip move _this)
?> (team:title our.bol src.bol)
:: send all updates from now on
[~ this]
::
++ peer-invitatory
|= pax=path
^- (quip move _this)
?> (team:title our.bol src.bol)
=/ inv=(unit invitatory) (~(get by invites) pax)
?~ inv !!
:_ this
[ost.bol %diff %invite-update [%invitatory u.inv]]~
::
++ poke-json
|= =json
^- (quip move _this)
?> (team:title our.bol src.bol)
(poke-invite-action (json-to-action json))
::
++ poke-invite-action
|= action=invite-action
^- (quip move _this)
?> (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)
::
==
::
++ handle-create
|= act=invite-action
^- (quip move _this)
?> ?=(%create -.act)
?: (~(has by invites) path.act)
[~ this]
:- (send-diff path.act act)
this(invites (~(put by invites) path.act *invitatory))
::
++ handle-delete
|= act=invite-action
^- (quip move _this)
?> ?=(%delete -.act)
?. (~(has by invites) path.act)
[~ this]
:- (send-diff path.act act)
this(invites (~(del by invites) path.act))
::
++ handle-invite
|= act=invite-action
^- (quip move _this)
?> ?=(%invite -.act)
?. (~(has by invites) path.act)
[~ this]
=/ container (~(got by invites) path.act)
=. uid.act (sham eny.bol)
=. container (~(put by container) uid.act invite.act)
:- (send-diff path.act act)
this(invites (~(put by invites) path.act container))
::
++ handle-accept
|= act=invite-action
^- (quip move _this)
?> ?=(%accept -.act)
?. (~(has by invites) path.act)
[~ this]
=/ container (~(got by invites) path.act)
=/ invite (~(get by container) uid.act)
?~ invite
[~ this]
=. container (~(del by container) uid.act)
:- (send-diff path.act [%accepted path.act uid.act u.invite])
this(invites (~(put by invites) path.act container))
::
++ handle-decline
|= act=invite-action
^- (quip move _this)
?> ?=(%decline -.act)
?. (~(has by invites) path.act)
[~ this]
=/ container (~(got by invites) path.act)
=/ invite (~(get by container) uid.act)
?~ invite
[~ this]
=. container (~(del by container) uid.act)
:- (send-diff path.act act)
this(invites (~(put by invites) path.act container))
::
++ update-subscribers
|= [pax=path upd=invite-update]
^- (list move)
%+ turn (prey:pubsub:userlib pax bol)
|= [=bone *]
[bone %diff %invite-update upd]
::
++ send-diff
|= [pax=path upd=invite-update]
^- (list move)
%- zing
:~ (update-subscribers /all upd)
(update-subscribers /updates upd)
(update-subscribers [%invitatory pax] upd)
==
::
--

View File

@ -0,0 +1,49 @@
:: invite-view: provide a json interface to invite-store
::
/+ *invite-json
::
|%
+$ move [bone card]
::
+$ card
$% [%peer wire dock path]
[%diff %json json]
==
--
::
|_ [bol=bowl:gall ~]
::
++ this .
::
++ prep
|= old=*
^- (quip move _this)
:_ this
[ost.bol %peer / [our.bol %invite-store] /updates]~
::
++ peer-primary
|= pax=path
^- (quip move _this)
?> (team:title our.bol src.bol)
:_ this
[ost.bol %diff %json (invites-to-json invites-scry)]~
::
++ diff-invite-update
|= [wir=wire upd=invite-update]
^- (quip move _this)
=/ updates-json (update-to-json upd)
:_ this
%+ turn (prey:pubsub:userlib /primary bol)
|= [=bone *]
[bone %diff %json updates-json]
::
++ quit
|= wir=wire
^- (quip move _this)
:_ this
[ost.bol %peer / [our.bol %invite-store] /updates]~
::
++ invites-scry
^- invites
.^(invites %gx /=invite-store/(scot %da now.bol)/all/noun)
--

View File

@ -102,6 +102,9 @@
%permission-store
%permission-hook
%permission-group-hook
%invite-store
%invite-hook
%invite-view
%chat-store
%chat-hook
%chat-view

View File

@ -0,0 +1,138 @@
/- *invite-store
|%
++ slan |=(mod/@tas |=(txt/@ta (need (slaw mod txt))))
::
++ seri ::: serial
=, dejs:format
^- $-(json serial)
(cu (slan %uv) so)
::
++ invites-to-json
|= inv=invites
^- json
%+ frond:enjs:format %invite-initial
%- pairs:enjs:format
%+ turn ~(tap by inv)
|= [=path =invitatory]
^- [cord json]
[(spat path) (invitatory-to-json invitatory)]
::
++ invitatory-to-json
|= =invitatory
^- json
=, enjs:format
%- pairs
%+ turn ~(tap by invitatory)
|= [=serial =invite]
^- [cord json]
[(scot %uv serial) (invite-to-json invite)]
::
++ invite-to-json
|= =invite
^- json
=, enjs:format
%- pairs
:~ [%path (path path.invite)]
[%ship (ship ship.invite)]
[%recipient (ship recipient.invite)]
[%app [%s app.invite]]
[%text [%s text.invite]]
==
::
++ update-to-json
|= upd=invite-update
=, enjs:format
^- json
%+ frond %invite-update
%- pairs
:~
?: =(%create -.upd)
?> ?=(%create -.upd)
[%create (pairs [%path (path path.upd)]~)]
?: =(%delete -.upd)
?> ?=(%delete -.upd)
[%delete (pairs [%path (path path.upd)]~)]
?: =(%accepted -.upd)
?> ?=(%accepted -.upd)
:- %accepted
%- pairs
:~ [%path (path path.upd)]
[%uid s+(scot %uv uid.upd)]
[%invite (invite-to-json invite.upd)]
==
?: =(%decline -.upd)
?> ?=(%decline -.upd)
:- %decline
%- pairs
:~ [%path (path path.upd)]
[%uid s+(scot %uv uid.upd)]
==
?: =(%invite -.upd)
?> ?=(%invite -.upd)
:- %invite
%- pairs
:~ [%path (path path.upd)]
[%uid s+(scot %uv uid.upd)]
[%invite (invite-to-json invite.upd)]
==
?: =(%invitatory -.upd)
?> ?=(%invitatory -.upd)
:- %invitatory
(invitatory-to-json invitatory.upd)
::
:: %noop
[*@t *json]
==
::
++ json-to-action
|= jon=json
^- invite-action
=, dejs:format
=< (parse-json jon)
|%
++ parse-json
%- of
:~ [%create create]
[%delete delete]
[%invite invite]
[%accept accept]
[%decline decline]
==
::
++ create
(ot [%path pa]~)
::
++ delete
(ot [%path pa]~)
::
++ invite
%- ot
:~ [%path pa]
[%uid seri]
[%invite invi]
==
::
++ accept
%- ot
:~ [%path pa]
[%uid seri]
==
::
++ decline
%- ot
:~ [%path pa]
[%uid seri]
==
::
++ invi
%- ot
:~ [%path pa]
[%ship (su ;~(pfix sig fed:ag))]
[%recipient (su ;~(pfix sig fed:ag))]
[%app (se %tas)]
[%text so]
==
--
--

View File

@ -0,0 +1,11 @@
/+ *invite-json
=, dejs:format
|_ act=invite-action
++ grab
|%
++ noun invite-action
++ json
|= jon=^json
(json-to-action jon)
--
--

View File

@ -0,0 +1,14 @@
/+ *invite-json
|_ inv=invites
::
++ grow
|%
++ json (invites-to-json inv)
--
::
++ grab
|%
++ noun invites
--
::
--

View File

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

View File

@ -0,0 +1,34 @@
|%
++ serial @uvH
::
+$ invite
$: =path
=ship
recipient=ship
app=@tas
text=cord
==
::
+$ invitatory (map serial invite) :: containing or conveying an invitation
::
+$ invites (map path invitatory)
::
+$ invite-base
$% [%create =path]
[%delete =path]
[%invite =path uid=serial =invite]
[%decline =path uid=serial]
==
::
+$ invite-action
$% invite-base
[%accept =path uid=serial]
==
::
+$ invite-update
$% invite-base
[%invitatory =invitatory]
[%accepted =path uid=serial =invite]
==
--