From 3b66821258974a82b280e189638926a33d8000f9 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Wed, 14 Apr 2021 19:59:17 +0100 Subject: [PATCH] move DM invite responsiblity to the server side --- src/components/views/dialogs/InviteDialog.tsx | 39 +++++++++++-------- src/createRoom.ts | 6 +++ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/components/views/dialogs/InviteDialog.tsx b/src/components/views/dialogs/InviteDialog.tsx index c89e61bd18..5ca7e3aec2 100644 --- a/src/components/views/dialogs/InviteDialog.tsx +++ b/src/components/views/dialogs/InviteDialog.tsx @@ -31,6 +31,7 @@ import Modal from "../../../Modal"; import {humanizeTime} from "../../../utils/humanize"; import createRoom, { canEncryptToAllUsers, ensureDMExists, findDMForUser, privateShouldBeEncrypted, + IInvite3PID, } from "../../../createRoom"; import {inviteMultipleToRoom, showCommunityInviteDialog} from "../../../RoomInvite"; import {Key} from "../../../Keyboard"; @@ -656,29 +657,33 @@ export default class InviteDialog extends React.PureComponent 1) { + createRoomOptions.createOpts = targetIds.reduce( + (roomOptions, address) => { + if (getAddressType(address) === 'email') { + const invite: IInvite3PID = { + id_server: client.getIdentityServerUrl(true), + medium: 'email', + address, + }; + roomOptions.invite_3pid.push(invite); + } else { + roomOptions.invite.push(address); + } + return roomOptions; + }, + { invite: [], invite_3pid: [] }, + ) } + + await createRoom(createRoomOptions); + this.props.onFinished(); } catch (err) { console.error(err); this.setState({ diff --git a/src/createRoom.ts b/src/createRoom.ts index a5343076ac..310d894266 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -90,6 +90,12 @@ export interface IOpts { parentSpace?: Room; } +export interface IInvite3PID { + id_server: string, + medium: 'email', + address: string, +} + /** * Create a new room, and switch to it. *