mirror of https://github.com/vector-im/riot-web
Merge pull request #5862 from matrix-org/gsouquet-start-dm
commit
4708c1682d
|
@ -31,6 +31,7 @@ import Modal from "../../../Modal";
|
||||||
import {humanizeTime} from "../../../utils/humanize";
|
import {humanizeTime} from "../../../utils/humanize";
|
||||||
import createRoom, {
|
import createRoom, {
|
||||||
canEncryptToAllUsers, ensureDMExists, findDMForUser, privateShouldBeEncrypted,
|
canEncryptToAllUsers, ensureDMExists, findDMForUser, privateShouldBeEncrypted,
|
||||||
|
IInvite3PID,
|
||||||
} from "../../../createRoom";
|
} from "../../../createRoom";
|
||||||
import {inviteMultipleToRoom, showCommunityInviteDialog} from "../../../RoomInvite";
|
import {inviteMultipleToRoom, showCommunityInviteDialog} from "../../../RoomInvite";
|
||||||
import {Key} from "../../../Keyboard";
|
import {Key} from "../../../Keyboard";
|
||||||
|
@ -618,13 +619,14 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
|
||||||
|
|
||||||
_startDm = async () => {
|
_startDm = async () => {
|
||||||
this.setState({busy: true});
|
this.setState({busy: true});
|
||||||
|
const client = MatrixClientPeg.get();
|
||||||
const targets = this._convertFilter();
|
const targets = this._convertFilter();
|
||||||
const targetIds = targets.map(t => t.userId);
|
const targetIds = targets.map(t => t.userId);
|
||||||
|
|
||||||
// Check if there is already a DM with these people and reuse it if possible.
|
// Check if there is already a DM with these people and reuse it if possible.
|
||||||
let existingRoom: Room;
|
let existingRoom: Room;
|
||||||
if (targetIds.length === 1) {
|
if (targetIds.length === 1) {
|
||||||
existingRoom = findDMForUser(MatrixClientPeg.get(), targetIds[0]);
|
existingRoom = findDMForUser(client, targetIds[0]);
|
||||||
} else {
|
} else {
|
||||||
existingRoom = DMRoomMap.shared().getDMRoomForIdentifiers(targetIds);
|
existingRoom = DMRoomMap.shared().getDMRoomForIdentifiers(targetIds);
|
||||||
}
|
}
|
||||||
|
@ -646,7 +648,6 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
|
||||||
// If so, enable encryption in the new room.
|
// If so, enable encryption in the new room.
|
||||||
const has3PidMembers = targets.some(t => t instanceof ThreepidMember);
|
const has3PidMembers = targets.some(t => t instanceof ThreepidMember);
|
||||||
if (!has3PidMembers) {
|
if (!has3PidMembers) {
|
||||||
const client = MatrixClientPeg.get();
|
|
||||||
const allHaveDeviceKeys = await canEncryptToAllUsers(client, targetIds);
|
const allHaveDeviceKeys = await canEncryptToAllUsers(client, targetIds);
|
||||||
if (allHaveDeviceKeys) {
|
if (allHaveDeviceKeys) {
|
||||||
createRoomOptions.encryption = true;
|
createRoomOptions.encryption = true;
|
||||||
|
@ -656,35 +657,41 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
|
||||||
|
|
||||||
// Check if it's a traditional DM and create the room if required.
|
// Check if it's a traditional DM and create the room if required.
|
||||||
// TODO: [Canonical DMs] Remove this check and instead just create the multi-person DM
|
// TODO: [Canonical DMs] Remove this check and instead just create the multi-person DM
|
||||||
let createRoomPromise = Promise.resolve(null) as Promise<string | null | boolean>;
|
try {
|
||||||
const isSelf = targetIds.length === 1 && targetIds[0] === MatrixClientPeg.get().getUserId();
|
const isSelf = targetIds.length === 1 && targetIds[0] === client.getUserId();
|
||||||
if (targetIds.length === 1 && !isSelf) {
|
if (targetIds.length === 1 && !isSelf) {
|
||||||
createRoomOptions.dmUserId = targetIds[0];
|
createRoomOptions.dmUserId = targetIds[0];
|
||||||
createRoomPromise = createRoom(createRoomOptions);
|
}
|
||||||
} else if (isSelf) {
|
|
||||||
createRoomPromise = createRoom(createRoomOptions);
|
|
||||||
} else {
|
|
||||||
// Create a boring room and try to invite the targets manually.
|
|
||||||
createRoomPromise = createRoom(createRoomOptions).then(roomId => {
|
|
||||||
return inviteMultipleToRoom(roomId, targetIds);
|
|
||||||
}).then(result => {
|
|
||||||
if (this._shouldAbortAfterInviteError(result)) {
|
|
||||||
return true; // abort
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// the createRoom call will show the room for us, so we don't need to worry about that.
|
if (targetIds.length > 1) {
|
||||||
createRoomPromise.then(abort => {
|
createRoomOptions.createOpts = targetIds.reduce(
|
||||||
if (abort === true) return; // only abort on true booleans, not roomIds or something
|
(roomOptions, address) => {
|
||||||
|
const type = getAddressType(address);
|
||||||
|
if (type === 'email') {
|
||||||
|
const invite: IInvite3PID = {
|
||||||
|
id_server: client.getIdentityServerUrl(true),
|
||||||
|
medium: 'email',
|
||||||
|
address,
|
||||||
|
};
|
||||||
|
roomOptions.invite_3pid.push(invite);
|
||||||
|
} else if (type === 'mx-user-id') {
|
||||||
|
roomOptions.invite.push(address);
|
||||||
|
}
|
||||||
|
return roomOptions;
|
||||||
|
},
|
||||||
|
{ invite: [], invite_3pid: [] },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
await createRoom(createRoomOptions);
|
||||||
this.props.onFinished();
|
this.props.onFinished();
|
||||||
}).catch(err => {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
this.setState({
|
this.setState({
|
||||||
busy: false,
|
busy: false,
|
||||||
errorText: _t("We couldn't create your DM."),
|
errorText: _t("We couldn't create your DM."),
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_inviteUsers = async () => {
|
_inviteUsers = async () => {
|
||||||
|
|
|
@ -90,6 +90,12 @@ export interface IOpts {
|
||||||
parentSpace?: Room;
|
parentSpace?: Room;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IInvite3PID {
|
||||||
|
id_server: string,
|
||||||
|
medium: 'email',
|
||||||
|
address: string,
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new room, and switch to it.
|
* Create a new room, and switch to it.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue