Ensure room is synced with account before sending invites
parent
8d95c012ef
commit
f89bbea3f1
|
@ -618,13 +618,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 +647,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,9 +656,8 @@ 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
|
||||||
|
|
||||||
try {
|
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];
|
||||||
await createRoom(createRoomOptions);
|
await createRoom(createRoomOptions);
|
||||||
|
@ -666,10 +665,15 @@ export default class InviteDialog extends React.PureComponent<IInviteDialogProps
|
||||||
await createRoom(createRoomOptions);
|
await createRoom(createRoomOptions);
|
||||||
} else {
|
} else {
|
||||||
const roomId = await createRoom(createRoomOptions);
|
const roomId = await createRoom(createRoomOptions);
|
||||||
|
/**
|
||||||
|
* To avoid race condition we want to make sure the room information
|
||||||
|
* is properly synced with the account before sending invites to targets
|
||||||
|
* It can otherwise result in a "Cannot find room" error
|
||||||
|
*/
|
||||||
|
await client.peekInRoom(roomId);
|
||||||
const invitesState = await inviteMultipleToRoom(roomId, targetIds);
|
const invitesState = await inviteMultipleToRoom(roomId, targetIds);
|
||||||
|
|
||||||
const abort = this._shouldAbortAfterInviteError(invitesState);
|
if (!this._shouldAbortAfterInviteError(invitesState)) {
|
||||||
if (abort === false) {
|
|
||||||
this.props.onFinished();
|
this.props.onFinished();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue