From abf12a3ddf2bcda8399b85abf971561b32ad5a0a Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 26 Mar 2020 17:31:31 +0100 Subject: [PATCH] Show EncryptionPanel straight away when there is an ongoing verification request for a user --- src/stores/RightPanelStore.js | 22 ++++++++++++++++++---- src/verification.js | 15 +++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/stores/RightPanelStore.js b/src/stores/RightPanelStore.js index 814f54b454..8869d0be42 100644 --- a/src/stores/RightPanelStore.js +++ b/src/stores/RightPanelStore.js @@ -15,6 +15,7 @@ limitations under the License. */ import dis from '../dispatcher'; +import {pendingVerificationRequestForUser} from '../verification'; import {Store} from 'flux/utils'; import SettingsStore, {SettingLevel} from "../settings/SettingsStore"; import {RIGHT_PANEL_PHASES, RIGHT_PANEL_PHASES_NO_ARGS} from "./RightPanelStorePhases"; @@ -135,7 +136,20 @@ export default class RightPanelStore extends Store { break; case 'set_right_panel_phase': { - const targetPhase = payload.phase; + let targetPhase = payload.phase; + let refireParams = payload.refireParams; + // redirect to EncryptionPanel if there is an ongoing verification request + if (targetPhase === RIGHT_PANEL_PHASES.RoomMemberInfo) { + const {member} = payload.refireParams; + const pendingRequest = pendingVerificationRequestForUser(member); + if (pendingRequest) { + targetPhase = RIGHT_PANEL_PHASES.EncryptionPanel; + refireParams = { + verificationRequest: pendingRequest, + member, + }; + } + } if (!RIGHT_PANEL_PHASES[targetPhase]) { console.warn(`Tried to switch right panel to unknown phase: ${targetPhase}`); return; @@ -153,7 +167,7 @@ export default class RightPanelStore extends Store { }); } } else { - if (targetPhase === this._state.lastRoomPhase && !payload.refireParams) { + if (targetPhase === this._state.lastRoomPhase && !refireParams) { this._setState({ showRoomPanel: !this._state.showRoomPanel, }); @@ -161,7 +175,7 @@ export default class RightPanelStore extends Store { this._setState({ lastRoomPhase: targetPhase, showRoomPanel: true, - lastRoomPhaseParams: payload.refireParams || {}, + lastRoomPhaseParams: refireParams || {}, }); } } @@ -170,7 +184,7 @@ export default class RightPanelStore extends Store { dis.dispatch({ action: 'after_right_panel_phase_change', phase: targetPhase, - ...(payload.refireParams || {}), + ...(refireParams || {}), }); break; } diff --git a/src/verification.js b/src/verification.js index d0f6fd7806..2231346478 100644 --- a/src/verification.js +++ b/src/verification.js @@ -111,12 +111,7 @@ export async function verifyUser(user) { if (!await enable4SIfNeeded()) { return; } - const cli = MatrixClientPeg.get(); - const dmRoom = findDMForUser(cli, user.userId); - let existingRequest; - if (dmRoom) { - existingRequest = cli.findVerificationRequestDMInProgress(dmRoom.roomId); - } + const existingRequest = pendingVerificationRequestForUser(user); dis.dispatch({ action: "set_right_panel_phase", phase: RIGHT_PANEL_PHASES.EncryptionPanel, @@ -126,3 +121,11 @@ export async function verifyUser(user) { }, }); } + +export function pendingVerificationRequestForUser(user) { + const cli = MatrixClientPeg.get(); + const dmRoom = findDMForUser(cli, user.userId); + if (dmRoom) { + return cli.findVerificationRequestDMInProgress(dmRoom.roomId); + } +}