Skip to content

Commit

Permalink
Allow invites to be cancelled (#6393)
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Sep 16, 2024
1 parent 4bea61f commit 1063ece
Show file tree
Hide file tree
Showing 34 changed files with 550 additions and 435 deletions.
14 changes: 12 additions & 2 deletions frontend/app/src/components/home/ChannelOrCommunityMembers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
break;
}
}
function onCancelCommunityInvite(ev: CustomEvent<string>): void {
dispatch("cancelCommunityInvite", ev.detail);
}
function onCancelGroupInvite(ev: CustomEvent<string>): void {
dispatch("cancelGroupInvite", ev.detail);
}
</script>

<ScopeToggle bind:selectedTab>
Expand All @@ -101,7 +109,8 @@
on:chatWith
on:showInviteUsers={showInviteCommunityUsers}
on:removeMember={onRemoveCommunityMember}
on:changeRole={onChangeCommunityRole} />
on:changeRole={onChangeCommunityRole}
on:cancelInvite={onCancelCommunityInvite} />

<Members
slot="channel"
Expand All @@ -117,7 +126,8 @@
on:chatWith
on:showInviteUsers={showInviteGroupUsers}
on:removeMember={onRemoveGroupMember}
on:changeRole={onChangeGroupRole} />
on:changeRole={onChangeGroupRole}
on:cancelInvite={onCancelGroupInvite} />
</ScopeToggle>

<style lang="scss">
Expand Down
68 changes: 47 additions & 21 deletions frontend/app/src/components/home/RightPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,14 @@
invitingUsers = true;
await client.inviteUsersToCommunity($selectedCommunity.id, userIds).then((resp) => {
switch (resp) {
case "success":
popRightPanelHistory();
if ($multiUserChat?.public ?? false) {
toastStore.showSuccessToast(i18nKey("communities.usersInvited"));
}
break;
default:
toastStore.showFailureToast(i18nKey("communities.errors.inviteUsers"));
break;
await client.inviteUsers($selectedCommunity.id, userIds).then((resp) => {
if (resp) {
popRightPanelHistory();
if ($multiUserChat?.public ?? false) {
toastStore.showSuccessToast(i18nKey("communities.usersInvited"));
}
} else {
toastStore.showFailureToast(i18nKey("communities.errors.inviteUsers"));
}
});
Expand All @@ -149,23 +146,21 @@
await client
.inviteUsers($multiUserChat.id, userIds)
.then((resp) => {
switch (resp) {
case "success":
popRightPanelHistory();
if (resp) {
popRightPanelHistory();
if ($multiUserChat?.public ?? false) {
toastStore.showSuccessToast(i18nKey("group.usersInvited"));
}
break;
default:
toastStore.showFailureToast(
} else {
toastStore.showFailureToast(
i18nKey(
"group.inviteUsersFailed",
undefined,
$multiUserChat.level,
true,
),
);
break;
}
})
.catch((err) => {
Expand Down Expand Up @@ -343,6 +338,30 @@
}
}
function onCancelCommunityInvite(ev: CustomEvent<string>) {
if ($selectedCommunity !== undefined) {
cancelInvite($selectedCommunity.id, ev.detail);
}
}
async function onCancelGroupInvite(ev: CustomEvent<string>) {
if (
$selectedChatId !== undefined &&
($selectedChatId.kind === "group_chat" || $selectedChatId.kind === "channel")
) {
cancelInvite($selectedChatId, ev.detail);
}
}
async function cancelInvite(id: MultiUserChatIdentifier | CommunityIdentifier, userId: string) {
const success = await client.cancelInvites(id, [userId]);
if (success) {
toastStore.showSuccessToast(i18nKey("cancelInviteSucceeded"));
} else {
toastStore.showFailureToast(i18nKey("cancelInviteFailed"));
}
}
$: threadRootEvent =
lastState.kind === "message_thread_panel" && $selectedChatId !== undefined
? findMessage($eventsStore, lastState.threadRootMessageId)
Expand Down Expand Up @@ -432,6 +451,8 @@
on:removeGroupMember={onRemoveGroupMember}
on:showInviteGroupUsers={showInviteGroupUsers}
on:changeGroupRole={onChangeGroupRole}
on:cancelGroupInvite={onCancelGroupInvite}
on:cancelCommunityInvite={onCancelCommunityInvite}
on:close={popRightPanelHistory}
on:chatWith />
{:else}
Expand All @@ -448,7 +469,9 @@
on:chatWith
on:showInviteUsers={showInviteCommunityUsers}
on:removeMember={onRemoveCommunityMember}
on:changeRole={onChangeCommunityRole} />
on:changeRole={onChangeCommunityRole}
on:cancelInvite={onCancelCommunityInvite}
/>
{/if}
{:else if lastState.kind === "invite_group_users" && $multiUserChat !== undefined}
{#if $multiUserChat.kind === "channel" && $selectedCommunity !== undefined}
Expand Down Expand Up @@ -488,7 +511,8 @@
on:chatWith
on:showInviteUsers={showInviteGroupUsers}
on:removeMember={onRemoveGroupMember}
on:changeRole={onChangeGroupRole} />
on:changeRole={onChangeGroupRole}
on:cancelInvite={onCancelGroupInvite} />
{:else if lastState.kind === "show_group_members" && $selectedChatId !== undefined && $multiUserChat !== undefined && $multiUserChat.kind === "channel" && $selectedCommunity !== undefined}
<ChannelOrCommunityMembers
selectedTab="channel"
Expand All @@ -506,7 +530,9 @@
on:showInviteGroupUsers={showInviteGroupUsers}
on:changeGroupRole={onChangeGroupRole}
on:close={popRightPanelHistory}
on:chatWith />
on:chatWith
on:cancelGroupInvite={onCancelGroupInvite}
on:cancelCommunityInvite={onCancelCommunityInvite} />
{:else if lastState.kind === "show_pinned" && $selectedChatId !== undefined && ($selectedChatId.kind === "group_chat" || $selectedChatId.kind === "channel") && $multiUserChat !== undefined}
<PinnedMessages
on:chatWith
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/components/home/addgroup/NewGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
candidateGroup.members.map((m) => m.user.userId),
)
.then((resp) => {
if (resp !== "success") {
if (!resp) {
Promise.reject("Unable to invite users to the new group");
}
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/communities/edit/Edit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@
return Promise.resolve();
}
return client
.inviteUsersToCommunity(
.inviteUsers(
{ kind: "community", communityId },
members.map((m) => m.user.userId),
)
.then((resp) => {
if (resp !== "success") {
if (!resp) {
Promise.reject("Unable to invite users to the new community");
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
export let canUninviteUser: boolean = false;
export let searchTerm: string = "";
function uninviteUser() {
dispatch("uninviteUser", user);
function cancelInvite() {
dispatch("cancelInvite", user.userId);
}
</script>

Expand All @@ -36,13 +36,13 @@
</span>
<span slot="menu">
<Menu>
<MenuItem on:click={uninviteUser}>
<MenuItem on:click={cancelInvite}>
<Cancel
size={$iconSize}
color={"var(--icon-inverted-txt)"}
slot="icon" />
<div slot="text">
<Translatable resourceKey={i18nKey("uninviteUser")} />
<Translatable resourceKey={i18nKey("cancelInvite")} />
</div>
</MenuItem>
</Menu>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
{:else if memberView === "invited"}
<div use:menuCloser class="user-list">
{#each invitedUsers as user}
<InvitedUser {user} {searchTerm} canUninviteUser={false} on:uninviteUser />
<InvitedUser {user} {searchTerm} canUninviteUser={client.canInviteUsers(collection.id)} on:cancelInvite />
{/each}
</div>
{/if}
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "无法加入黑名单",
"blockUserSucceeded": "该用户已被加入黑名单",
"cancel": "取消",
"cancelInvite": "取消邀请",
"cancelInviteFailed": "取消邀请时出错",
"cancelInviteSucceeded": "邀请已取消",
"challenge": {
"alreadyRegistered": "请关闭并稍后重试",
"failed": "挑战失败。请重试。",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "Benutzer kann nicht blockiert werden",
"blockUserSucceeded": "Benutzer wurde gesperrt",
"cancel": "Abbrechen",
"cancelInvite": "Einladung abbrechen",
"cancelInviteFailed": "Fehler beim Abbrechen der Einladung",
"cancelInviteSucceeded": "Einladung abgebrochen",
"challenge": {
"alreadyRegistered": "Bitte schließen und später erneut versuchen",
"failed": "Herausforderung fehlgeschlagen. Bitte versuchen Sie es erneut.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "Unable to block user",
"blockUserSucceeded": "User has been blocked",
"cancel": "Cancel",
"cancelInvite": "Cancel invite",
"cancelInviteFailed": "Error cancelling invite",
"cancelInviteSucceeded": "Invite cancelled",
"challenge": {
"alreadyRegistered": "Please close and try again later",
"failed": "Challenge failed. Please try again.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "No se puede bloquear al usuario",
"blockUserSucceeded": "El usuario ha sido bloqueado",
"cancel": "Cancelar",
"cancelInvite": "Cancelar invitación",
"cancelInviteFailed": "Error al cancelar la invitación",
"cancelInviteSucceeded": "Invitación cancelada",
"challenge": {
"alreadyRegistered": "Cierra y vuelve a intentarlo más tarde.",
"failed": "El desafío falló. Inténtalo de nuevo.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "مسدود کردن کاربر ممکن نیست",
"blockUserSucceeded": "کاربر مسدود شده است",
"cancel": "لغو کنید",
"cancelInvite": "لغو دعوت",
"cancelInviteFailed": "خطا در لغو دعوت",
"cancelInviteSucceeded": "دعوت لغو شد",
"challenge": {
"alreadyRegistered": "لطفاً ببندید و بعداً دوباره امتحان کنید",
"failed": "چالش شکست خورد. لطفا دوباره تلاش کنید.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "Impossible de bloquer l'utilisateur",
"blockUserSucceeded": "L'utilisateur a été bloqué",
"cancel": "Annuler",
"cancelInvite": "Annuler l'invitation",
"cancelInviteFailed": "Erreur lors de l'annulation de l'invitation",
"cancelInviteSucceeded": "Invitation annulée",
"challenge": {
"alreadyRegistered": "Veuillez fermer et réessayer plus tard",
"failed": "Le défi a échoué. Veuillez réessayer.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "उपयोगकर्ता को ब्लॉक करने में असमर्थ",
"blockUserSucceeded": "उपयोगकर्ता को ब्लॉक कर दिया गया है",
"cancel": "रद्द करें",
"cancelInvite": "आमंत्रण रद्द करें",
"cancelInviteFailed": "आमंत्रण रद्द करने में त्रुटि",
"cancelInviteSucceeded": "आमंत्रण रद्द किया गया",
"challenge": {
"alreadyRegistered": "कृपया बंद करें और बाद में पुनः प्रयास करें",
"failed": "चुनौती विफल. कृपया पुनः प्रयास करें.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "Impossibile bloccare l'utente",
"blockUserSucceeded": "L'utente è stato bloccato",
"cancel": "Annulla",
"cancelInvite": "Annulla invito",
"cancelInviteFailed": "Errore durante l'annullamento dell'invito",
"cancelInviteSucceeded": "Invito annullato",
"challenge": {
"alreadyRegistered": "Per favore chiudi e riprova più tardi",
"failed": "Sfida fallita. Per favore riprova.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/iw.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "לא ניתן לחסום משתמש",
"blockUserSucceeded": "המשתמש נחסם",
"cancel": "לְבַטֵל",
"cancelInvite": "בטל הזמנה",
"cancelInviteFailed": "שגיאה בביטול ההזמנה",
"cancelInviteSucceeded": "ההזמנה בוטלה",
"challenge": {
"alreadyRegistered": "אנא סגור ונסה שוב מאוחר יותר",
"failed": "האתגר נכשל. בבקשה נסה שוב.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "ユーザーをブロックできませんでした",
"blockUserSucceeded": "ユーザーはブロックされました",
"cancel": "キャンセル",
"cancelInvite": "招待をキャンセル",
"cancelInviteFailed": "招待のキャンセル中にエラーが発生しました",
"cancelInviteSucceeded": "招待をキャンセルしました",
"challenge": {
"alreadyRegistered": "閉じて、後でもう一度お試しください",
"failed": "チャレンジに失敗しました。もう一度お試しください。",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "Nie można zablokować użytkownika",
"blockUserSucceeded": "Użytkownik został zablokowany",
"cancel": "Anulować",
"cancelInvite": "Anuluj zaproszenie",
"cancelInviteFailed": "Błąd podczas anulowania zaproszenia",
"cancelInviteSucceeded": "Zaproszenie anulowane",
"challenge": {
"alreadyRegistered": "Zamknij i spróbuj ponownie później",
"failed": "Wyzwanie nie powiodło się. Proszę spróbuj ponownie.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "Не удалось заблокировать пользователя",
"blockUserSucceeded": "Пользователь заблокирован",
"cancel": "Отмена",
"cancelInvite": "Отменить приглашение",
"cancelInviteFailed": "Ошибка отмены приглашения",
"cancelInviteSucceeded": "Приглашение отменено",
"challenge": {
"alreadyRegistered": "Пожалуйста, закройте и повторите попытку позже.",
"failed": "Вызов не удался. Пожалуйста, попробуйте еще раз.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "Не вдалося заблокувати користувача",
"blockUserSucceeded": "Користувача заблоковано",
"cancel": "Скасувати",
"cancelInvite": "Скасувати запрошення",
"cancelInviteFailed": "Помилка скасування запрошення",
"cancelInviteSucceeded": "Запрошення скасовано",
"challenge": {
"alreadyRegistered": "Будь ласка, закрийте та повторіть спробу пізніше",
"failed": "Виклик не виконано. Будь ласка спробуйте ще раз.",
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/i18n/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"blockUserFailed": "Không thể chặn người dùng",
"blockUserSucceeded": "Người dùng đã bị chặn",
"cancel": "Hủy bỏ",
"cancelInvite": "Hủy lời mời",
"cancelInviteFailed": "Lỗi khi hủy lời mời",
"cancelInviteSucceeded": "Lời mời đã hủy",
"challenge": {
"alreadyRegistered": "Vui lòng đóng và thử lại sau",
"failed": "Thử thách không thành công. Vui lòng thử lại.",
Expand Down
14 changes: 14 additions & 0 deletions frontend/openchat-agent/src/services/community/candid/idl.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ export const idlFactory = ({ IDL }) => {
'CannotBlockSelf' : IDL.Null,
'CannotBlockUser' : IDL.Null,
});
const CancelInvitesArgs = IDL.Record({
'channel_id' : IDL.Opt(ChannelId),
'user_ids' : IDL.Vec(UserId),
});
const CancelInvitesResponse = IDL.Variant({
'ChannelNotFound' : IDL.Null,
'NotAuthorized' : IDL.Null,
'Success' : IDL.Null,
});
const CancelP2PSwapArgs = IDL.Record({
'channel_id' : ChannelId,
'message_id' : MessageId,
Expand Down Expand Up @@ -2072,6 +2081,11 @@ export const idlFactory = ({ IDL }) => {
),
'add_reaction' : IDL.Func([AddReactionArgs], [AddReactionResponse], []),
'block_user' : IDL.Func([BlockUserArgs], [BlockUserResponse], []),
'cancel_invites' : IDL.Func(
[CancelInvitesArgs],
[CancelInvitesResponse],
[],
),
'cancel_p2p_swap' : IDL.Func(
[CancelP2PSwapArgs],
[CancelP2PSwapResponse],
Expand Down
Loading

0 comments on commit 1063ece

Please sign in to comment.