make sure to have roomId of DM when starting verif. req.

pull/21833/head
Bruno Windels 2019-12-19 16:43:10 +00:00
parent b866c16071
commit b80bfd04b2
3 changed files with 27 additions and 25 deletions

View File

@ -24,8 +24,7 @@ import sdk from '../../../index';
import * as FormattingUtils from '../../../utils/FormattingUtils'; import * as FormattingUtils from '../../../utils/FormattingUtils';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import {verificationMethods} from 'matrix-js-sdk/lib/crypto'; import {verificationMethods} from 'matrix-js-sdk/lib/crypto';
import DMRoomMap from '../../../utils/DMRoomMap'; import {ensureDMExists} from "../../../createRoom";
import createRoom from "../../../createRoom";
import dis from "../../../dispatcher"; import dis from "../../../dispatcher";
import SettingsStore from '../../../settings/SettingsStore'; import SettingsStore from '../../../settings/SettingsStore';
@ -322,23 +321,7 @@ export default class DeviceVerifyDialog extends React.Component {
} }
async function ensureDMExistsAndOpen(userId) { async function ensureDMExistsAndOpen(userId) {
const client = MatrixClientPeg.get(); const roomId = ensureDMExists(MatrixClientPeg.get(), userId);
const roomIds = DMRoomMap.shared().getDMRoomsForUserId(userId);
const rooms = roomIds.map(id => client.getRoom(id));
const suitableDMRooms = rooms.filter(r => {
if (r && r.getMyMembership() === "join") {
const member = r.getMember(userId);
return member && (member.membership === "invite" || member.membership === "join");
}
return false;
});
let roomId;
if (suitableDMRooms.length) {
const room = suitableDMRooms[0];
roomId = room.roomId;
} else {
roomId = await createRoom({dmUserId: userId, spinner: false, andView: false});
}
// don't use andView and spinner in createRoom, together, they cause this dialog to close and reopen, // don't use andView and spinner in createRoom, together, they cause this dialog to close and reopen,
// we causes us to loose the verifier and restart, and we end up having two verification requests // we causes us to loose the verifier and restart, and we end up having two verification requests
dis.dispatch({ dis.dispatch({

View File

@ -18,6 +18,7 @@ import React from 'react';
import EncryptionInfo from "./EncryptionInfo"; import EncryptionInfo from "./EncryptionInfo";
import VerificationPanel from "./VerificationPanel"; import VerificationPanel from "./VerificationPanel";
import MatrixClientPeg from "../../../MatrixClientPeg"; import MatrixClientPeg from "../../../MatrixClientPeg";
import {ensureDMExists} from "../../../createRoom";
export default class EncryptionPanel extends React.PureComponent { export default class EncryptionPanel extends React.PureComponent {
constructor(props) { constructor(props) {
@ -40,9 +41,8 @@ export default class EncryptionPanel extends React.PureComponent {
_onStartVerification = async () => { _onStartVerification = async () => {
const client = MatrixClientPeg.get(); const client = MatrixClientPeg.get();
const {member} = this.props; const {member} = this.props;
// TODO: get the room id of the DM here? const roomId = await ensureDMExists(client, member.userId);
// will this panel be shown in non-DM rooms? const verificationRequest = await client.requestVerificationDM(member.userId, roomId);
const verificationRequest = await client.requestVerificationDM(member.userId, member.roomId);
this.setState({verificationRequest}); this.setState({verificationRequest});
}; };
} }

View File

@ -1,5 +1,6 @@
/* /*
Copyright 2015, 2016 OpenMarket Ltd Copyright 2015, 2016 OpenMarket Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -20,7 +21,7 @@ import sdk from './index';
import { _t } from './languageHandler'; import { _t } from './languageHandler';
import dis from "./dispatcher"; import dis from "./dispatcher";
import * as Rooms from "./Rooms"; import * as Rooms from "./Rooms";
import DMRoomMap from "./utils/DMRoomMap";
import {getAddressType} from "./UserAddress"; import {getAddressType} from "./UserAddress";
/** /**
@ -35,7 +36,7 @@ import {getAddressType} from "./UserAddress";
* @returns {Promise} which resolves to the room id, or null if the * @returns {Promise} which resolves to the room id, or null if the
* action was aborted or failed. * action was aborted or failed.
*/ */
function createRoom(opts) { export default function createRoom(opts) {
opts = opts || {}; opts = opts || {};
if (opts.spinner === undefined) opts.spinner = true; if (opts.spinner === undefined) opts.spinner = true;
@ -140,4 +141,22 @@ function createRoom(opts) {
}); });
} }
module.exports = createRoom; export async function ensureDMExists(client, userId) {
const roomIds = DMRoomMap.shared().getDMRoomsForUserId(userId);
const rooms = roomIds.map(id => client.getRoom(id));
const suitableDMRooms = rooms.filter(r => {
if (r && r.getMyMembership() === "join") {
const member = r.getMember(userId);
return member && (member.membership === "invite" || member.membership === "join");
}
return false;
});
let roomId;
if (suitableDMRooms.length) {
const room = suitableDMRooms[0];
roomId = room.roomId;
} else {
roomId = await createRoom({dmUserId: userId, spinner: false, andView: false});
}
return roomId;
}