Merge pull request #4070 from matrix-org/bwindels/oneverifrequest
Find existing requests when starting a new verification requestpull/21833/head
commit
93674ec781
|
@ -69,6 +69,7 @@ const EncryptionPanel = ({verificationRequest, member, onClose, layout}) => {
|
||||||
const roomId = await ensureDMExists(cli, member.userId);
|
const roomId = await ensureDMExists(cli, member.userId);
|
||||||
const verificationRequest = await cli.requestVerificationDM(member.userId, roomId);
|
const verificationRequest = await cli.requestVerificationDM(member.userId, roomId);
|
||||||
setRequest(verificationRequest);
|
setRequest(verificationRequest);
|
||||||
|
setPhase(verificationRequest.phase);
|
||||||
}, [member.userId]);
|
}, [member.userId]);
|
||||||
|
|
||||||
const requested = request && (phase === PHASE_REQUESTED || phase === undefined);
|
const requested = request && (phase === PHASE_REQUESTED || phase === undefined);
|
||||||
|
|
|
@ -25,7 +25,7 @@ import dis from '../../../dispatcher';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
import * as sdk from '../../../index';
|
import * as sdk from '../../../index';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import createRoom from '../../../createRoom';
|
import createRoom, {findDMForUser} from '../../../createRoom';
|
||||||
import DMRoomMap from '../../../utils/DMRoomMap';
|
import DMRoomMap from '../../../utils/DMRoomMap';
|
||||||
import AccessibleButton from '../elements/AccessibleButton';
|
import AccessibleButton from '../elements/AccessibleButton';
|
||||||
import SdkConfig from '../../../SdkConfig';
|
import SdkConfig from '../../../SdkConfig';
|
||||||
|
@ -169,10 +169,19 @@ async function verifyDevice(userId, device) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyUser(user) {
|
function verifyUser(user) {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
const dmRoom = findDMForUser(cli, user.userId);
|
||||||
|
let existingRequest;
|
||||||
|
if (dmRoom) {
|
||||||
|
existingRequest = cli.findVerificationRequestDMInProgress(dmRoom.roomId);
|
||||||
|
}
|
||||||
dis.dispatch({
|
dis.dispatch({
|
||||||
action: "set_right_panel_phase",
|
action: "set_right_panel_phase",
|
||||||
phase: RIGHT_PANEL_PHASES.EncryptionPanel,
|
phase: RIGHT_PANEL_PHASES.EncryptionPanel,
|
||||||
refireParams: {member: user},
|
refireParams: {
|
||||||
|
member: user,
|
||||||
|
verificationRequest: existingRequest,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -258,7 +258,11 @@ export default class VerificationPanel extends React.PureComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.request.on("change", this._onRequestChange);
|
const {request} = this.props;
|
||||||
|
request.on("change", this._onRequestChange);
|
||||||
|
if (request.verifier) {
|
||||||
|
this.setState({sasEvent: request.verifier.sasEvent});
|
||||||
|
}
|
||||||
this._onRequestChange();
|
this._onRequestChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ export default function createRoom(opts) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function ensureDMExists(client, userId) {
|
export function findDMForUser(client, userId) {
|
||||||
const roomIds = DMRoomMap.shared().getDMRoomsForUserId(userId);
|
const roomIds = DMRoomMap.shared().getDMRoomsForUserId(userId);
|
||||||
const rooms = roomIds.map(id => client.getRoom(id));
|
const rooms = roomIds.map(id => client.getRoom(id));
|
||||||
const suitableDMRooms = rooms.filter(r => {
|
const suitableDMRooms = rooms.filter(r => {
|
||||||
|
@ -169,10 +169,16 @@ export async function ensureDMExists(client, userId) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
let roomId;
|
|
||||||
if (suitableDMRooms.length) {
|
if (suitableDMRooms.length) {
|
||||||
const room = suitableDMRooms[0];
|
return suitableDMRooms[0];
|
||||||
roomId = room.roomId;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function ensureDMExists(client, userId) {
|
||||||
|
const existingDMRoom = findDMForUser(client, userId);
|
||||||
|
let roomId;
|
||||||
|
if (existingDMRoom) {
|
||||||
|
roomId = existingDMRoom.roomId;
|
||||||
} else {
|
} else {
|
||||||
roomId = await createRoom({dmUserId: userId, spinner: false, andView: false});
|
roomId = await createRoom({dmUserId: userId, spinner: false, andView: false});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue