From d49fbf25f71b124f57ccd9e60821eee7d2c71d13 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 13 Feb 2020 14:32:33 +0100 Subject: [PATCH 1/3] check if verifier sasEvent was already set on mount this allow the verification panel to fully recover the UI state from an on-going verification request --- src/components/views/right_panel/VerificationPanel.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/views/right_panel/VerificationPanel.js b/src/components/views/right_panel/VerificationPanel.js index a8d4ce733b..7474f0ef48 100644 --- a/src/components/views/right_panel/VerificationPanel.js +++ b/src/components/views/right_panel/VerificationPanel.js @@ -258,7 +258,11 @@ export default class VerificationPanel extends React.PureComponent { }; 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(); } From 68197a1d183a4c4a7b19eeeb2859131ced3a64ed Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 13 Feb 2020 14:33:35 +0100 Subject: [PATCH 2/3] also update phase after starting request as it might now be a request that is already ongoing --- src/components/views/right_panel/EncryptionPanel.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/views/right_panel/EncryptionPanel.js b/src/components/views/right_panel/EncryptionPanel.js index 2e9365fca3..89c9a26e92 100644 --- a/src/components/views/right_panel/EncryptionPanel.js +++ b/src/components/views/right_panel/EncryptionPanel.js @@ -69,6 +69,7 @@ const EncryptionPanel = ({verificationRequest, member, onClose, layout}) => { const roomId = await ensureDMExists(cli, member.userId); const verificationRequest = await cli.requestVerificationDM(member.userId, roomId); setRequest(verificationRequest); + setPhase(verificationRequest.phase); }, [member.userId]); const requested = request && (phase === PHASE_REQUESTED || phase === undefined); From 4b7cc12daa7e25b550e028be3399e122a45b2918 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 13 Feb 2020 14:34:44 +0100 Subject: [PATCH 3/3] check if there is already a request in progress when clicking verify and go straight there instead of first showing EncryptionInfo panel --- src/components/views/right_panel/UserInfo.js | 13 +++++++++++-- src/createRoom.js | 14 ++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/components/views/right_panel/UserInfo.js b/src/components/views/right_panel/UserInfo.js index 315035db96..1174f45640 100644 --- a/src/components/views/right_panel/UserInfo.js +++ b/src/components/views/right_panel/UserInfo.js @@ -25,7 +25,7 @@ import dis from '../../../dispatcher'; import Modal from '../../../Modal'; import * as sdk from '../../../index'; import { _t } from '../../../languageHandler'; -import createRoom from '../../../createRoom'; +import createRoom, {findDMForUser} from '../../../createRoom'; import DMRoomMap from '../../../utils/DMRoomMap'; import AccessibleButton from '../elements/AccessibleButton'; import SdkConfig from '../../../SdkConfig'; @@ -169,10 +169,19 @@ async function verifyDevice(userId, device) { } function verifyUser(user) { + const cli = MatrixClientPeg.get(); + const dmRoom = findDMForUser(cli, user.userId); + let existingRequest; + if (dmRoom) { + existingRequest = cli.findVerificationRequestDMInProgress(dmRoom.roomId); + } dis.dispatch({ action: "set_right_panel_phase", phase: RIGHT_PANEL_PHASES.EncryptionPanel, - refireParams: {member: user}, + refireParams: { + member: user, + verificationRequest: existingRequest, + }, }); } diff --git a/src/createRoom.js b/src/createRoom.js index c25b618dc6..d4575633b3 100644 --- a/src/createRoom.js +++ b/src/createRoom.js @@ -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 rooms = roomIds.map(id => client.getRoom(id)); const suitableDMRooms = rooms.filter(r => { @@ -169,10 +169,16 @@ export async function ensureDMExists(client, userId) { } return false; }); - let roomId; if (suitableDMRooms.length) { - const room = suitableDMRooms[0]; - roomId = room.roomId; + return suitableDMRooms[0]; + } +} + +export async function ensureDMExists(client, userId) { + const existingDMRoom = findDMForUser(client, userId); + let roomId; + if (existingDMRoom) { + roomId = existingDMRoom.roomId; } else { roomId = await createRoom({dmUserId: userId, spinner: false, andView: false}); }