From 073c2c525f6a9270b9666b573a7d28ba8510f9b8 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 19 Mar 2020 16:31:23 +0100 Subject: [PATCH] Add "legacy verify" button to untrusted session dialog --- src/i18n/strings/en_EN.json | 3 +- src/verification.js | 69 +++++++++++++++++++++++-------------- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index c3befa2298..e04946b5a3 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -294,8 +294,9 @@ "Not Trusted": "Not Trusted", "%(name)s (%(userId)s) signed in to a new session without verifying it:": "%(name)s (%(userId)s) signed in to a new session without verifying it:", "Ask this user to verify their session, or manually verify it below.": "Ask this user to verify their session, or manually verify it below.", + "Legacy Verify Device": "Legacy Verify Device", + "Verify Device by Emoji": "Verify Device by Emoji", "Done": "Done", - "Manually Verify": "Manually Verify", "%(displayName)s is typing …": "%(displayName)s is typing …", "%(names)s and %(count)s others are typing …|other": "%(names)s and %(count)s others are typing …", "%(names)s and %(count)s others are typing …|one": "%(names)s and one other is typing …", diff --git a/src/verification.js b/src/verification.js index 4443079b95..00905acf8e 100644 --- a/src/verification.js +++ b/src/verification.js @@ -39,38 +39,55 @@ async function enable4SIfNeeded() { return true; } +function UntrustedDeviceDialog(props) { + const {device, user, onFinished} = props; + const BaseDialog = sdk.getComponent("dialogs.BaseDialog"); + const AccessibleButton = sdk.getComponent("elements.AccessibleButton"); + return +
+

{_t("%(name)s (%(userId)s) signed in to a new session without verifying it:", {name: user.displayName, userId: user.userId})}

+

{device.getDisplayName()} ({device.deviceId})

+

{_t("Ask this user to verify their session, or manually verify it below.")}

+
+
+ onFinished("legacy")}>{_t("Legacy Verify Device")} + onFinished("sas")}>{_t("Verify Device by Emoji")} + onFinished()}>{_t("Done")} +
+
; +} + export async function verifyDevice(user, device) { if (!await enable4SIfNeeded()) { return; } - const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog"); - Modal.createTrackedDialog("Verification warning", "unverified session", QuestionDialog, { - headerImage: require("../res/img/e2e/warning.svg"), - title: _t("Not Trusted"), - description:
-

{_t("%(name)s (%(userId)s) signed in to a new session without verifying it:", {name: user.displayName, userId: user.userId})}

-

{device.getDisplayName()} ({device.deviceId})

-

{_t("Ask this user to verify their session, or manually verify it below.")}

-
, - onFinished: async (doneClicked) => { - const manuallyVerifyClicked = !doneClicked; - if (!manuallyVerifyClicked) { - return; + Modal.createTrackedDialog("Verification warning", "unverified session", UntrustedDeviceDialog, { + user, + device, + onFinished: async (action) => { + if (action === "sas") { + const cli = MatrixClientPeg.get(); + const verificationRequestPromise = cli.legacyDeviceVerification( + user.userId, + device.deviceId, + verificationMethods.SAS, + ); + dis.dispatch({ + action: "set_right_panel_phase", + phase: RIGHT_PANEL_PHASES.EncryptionPanel, + refireParams: {member: user, verificationRequestPromise}, + }); + } else if (action === "legacy") { + const ManualDeviceKeyVerificationDialog = sdk.getComponent("dialogs.ManualDeviceKeyVerificationDialog"); + Modal.createTrackedDialog("Legacy verify session", "legacy verify session", ManualDeviceKeyVerificationDialog, { + userId: user.userId, + device, + }); } - const cli = MatrixClientPeg.get(); - const verificationRequestPromise = cli.legacyDeviceVerification( - user.userId, - device.deviceId, - verificationMethods.SAS, - ); - dis.dispatch({ - action: "set_right_panel_phase", - phase: RIGHT_PANEL_PHASES.EncryptionPanel, - refireParams: {member: user, verificationRequestPromise}, - }); }, - primaryButton: _t("Done"), - cancelButton: _t("Manually Verify"), }); }