chat: auto-invite on addition to group

This commit is contained in:
Logan Allen 2020-02-07 15:52:55 -08:00
parent deb3d26d3f
commit 3e94033196
5 changed files with 26 additions and 43 deletions

View File

@ -270,25 +270,35 @@
++ fact-permission-update
|= [wir=wire fact=permission-update]
^- (quip card _state)
|^
:_ state
?+ -.fact ~
%add (handle-permissions [%add path.fact who.fact])
%remove (handle-permissions [%remove path.fact who.fact])
==
::
++ handle-permissions
|= [kind=?(%add %remove) pax=path who=(set ship)]
^- (list card)
?> ?=([* *] pax)
%- zing
%+ turn ~(tap in who)
|= =ship
?: (permitted-scry [(scot %p ship) pax])
~
:: if ship is not permitted, kick their subscription
=/ mail-path
(oust [(dec (lent t.pax)) (lent t.pax)] `(list @t)`t.pax)
[%give %kick [%mailbox mail-path]~ `ship]~
::
++ handle-permissions
|= [kind=?(%add %remove) pax=path who=(set ship)]
^- (list card)
?> ?=([* *] pax)
%- zing
%+ turn ~(tap in who)
|= =ship
?: (permitted-scry [(scot %p ship) pax])
?: ?|(=(kind %remove) =(ship our.bol)) ~
:: if ship has just been added to the permitted group,
:: send them an invite
~[(send-invite pax ship)]
:: if ship is not permitted, kick their subscription
[%give %kick [%mailbox pax]~ `ship]~
::
++ send-invite
|= [=path =ship]
^- card
=/ =invite [our.bol %chat-hook path ship '']
=/ act=invite-action [%invite /chat (shaf %msg-uid eny.bol) invite]
[%pass / %agent [our.bol %invite-hook] %poke %invite-action !>(act)]
--
::
++ fact-chat-update
|= [wir=wire fact=chat-update]

View File

@ -206,9 +206,6 @@
(create-managed-group path.act security.act members.act)
(create-security path.act security.act)
~[(permission-hook-poke [%add-owned path.act path.act])]
%+ turn ~(tap in members.act)
|= =ship
(send-invite-poke path.act ship)
==
::
%delete

File diff suppressed because one or more lines are too long

View File

@ -28,8 +28,7 @@ class UrbitApi {
this.invite = {
accept: this.inviteAccept.bind(this),
decline: this.inviteDecline.bind(this),
invite: this.inviteInvite.bind(this)
decline: this.inviteDecline.bind(this)
};
}
@ -155,24 +154,6 @@ class UrbitApi {
this.action("invite-store", "json", data);
}
inviteInvite(path, ship) {
this.action("invite-hook", "json",
{
invite: {
path: '/chat',
invite: {
path,
ship: `~${window.ship}`,
recipient: ship,
app: 'chat-hook',
text: `~${window.ship}${path}`,
},
uid: uuid()
}
}
);
}
inviteAccept(uid) {
this.inviteAction({
accept: {

View File

@ -52,11 +52,6 @@ export class InviteElement extends Component {
members: ''
}, () => {
props.api.groups.add(aud, props.path);
if (props.permissions.kind === 'white') {
aud.forEach((ship) => {
props.api.invite.invite(props.path, ship);
});
}
});
}