From 0618d82ccbbfd7a59c0f397f91a8c0083d76b8c9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 15 Jun 2020 17:41:22 +0100 Subject: [PATCH 1/3] Look for existing verification requests after login Fixes https://github.com/vector-im/riot-web/issues/13462 Requires https://github.com/matrix-org/matrix-js-sdk/pull/1405 --- src/stores/SetupEncryptionStore.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/stores/SetupEncryptionStore.js b/src/stores/SetupEncryptionStore.js index cc64e24a03..742b16ec98 100644 --- a/src/stores/SetupEncryptionStore.js +++ b/src/stores/SetupEncryptionStore.js @@ -49,6 +49,12 @@ export class SetupEncryptionStore extends EventEmitter { MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest); MatrixClientPeg.get().on('userTrustStatusChanged', this._onUserTrustStatusChanged); + const cli = MatrixClientPeg.get(); + const requestsInProgress = cli.getVerificationRequestsToDeviceInProgress(cli.getUserId()); + if (requestsInProgress.length) { + this._setActiveVerificationRequest(requestsInProgress[0]); + } + this.fetchKeyInfo(); } @@ -168,16 +174,8 @@ export class SetupEncryptionStore extends EventEmitter { } } - onVerificationRequest = async (request) => { - if (request.otherUserId !== MatrixClientPeg.get().getUserId()) return; - - if (this.verificationRequest) { - this.verificationRequest.off("change", this.onVerificationRequestChange); - } - this.verificationRequest = request; - await request.accept(); - request.on("change", this.onVerificationRequestChange); - this.emit("update"); + onVerificationRequest = (request) => { + this._setActiveVerificationRequest(request); } onVerificationRequestChange = async () => { @@ -218,4 +216,16 @@ export class SetupEncryptionStore extends EventEmitter { // async - ask other clients for keys, if necessary MatrixClientPeg.get()._crypto.cancelAndResendAllOutgoingKeyRequests(); } + + async _setActiveVerificationRequest(request) { + if (request.otherUserId !== MatrixClientPeg.get().getUserId()) return; + + if (this.verificationRequest) { + this.verificationRequest.off("change", this.onVerificationRequestChange); + } + this.verificationRequest = request; + await request.accept(); + request.on("change", this.onVerificationRequestChange); + this.emit("update"); + } } From d90645f0ea94442d37d14dbcb1782170463a025b Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 15 Jun 2020 17:46:22 +0100 Subject: [PATCH 2/3] add comment --- src/stores/SetupEncryptionStore.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/stores/SetupEncryptionStore.js b/src/stores/SetupEncryptionStore.js index 742b16ec98..a9a0ad4aa2 100644 --- a/src/stores/SetupEncryptionStore.js +++ b/src/stores/SetupEncryptionStore.js @@ -52,6 +52,9 @@ export class SetupEncryptionStore extends EventEmitter { const cli = MatrixClientPeg.get(); const requestsInProgress = cli.getVerificationRequestsToDeviceInProgress(cli.getUserId()); if (requestsInProgress.length) { + // If there are multiple, we take the first. Equally if the user sends another request from + // another device after this screen has been shown, we'll switch to the new one, so this + // generally doesn't support multiple requests. this._setActiveVerificationRequest(requestsInProgress[0]); } From 89a72b768556a94b4a175e701015c4be0d01b70d Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 16 Jun 2020 14:53:13 +0100 Subject: [PATCH 3/3] Take the last request (ie. the most recent) --- src/stores/SetupEncryptionStore.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stores/SetupEncryptionStore.js b/src/stores/SetupEncryptionStore.js index a9a0ad4aa2..4cdc845419 100644 --- a/src/stores/SetupEncryptionStore.js +++ b/src/stores/SetupEncryptionStore.js @@ -52,10 +52,10 @@ export class SetupEncryptionStore extends EventEmitter { const cli = MatrixClientPeg.get(); const requestsInProgress = cli.getVerificationRequestsToDeviceInProgress(cli.getUserId()); if (requestsInProgress.length) { - // If there are multiple, we take the first. Equally if the user sends another request from + // If there are multiple, we take the most recent. Equally if the user sends another request from // another device after this screen has been shown, we'll switch to the new one, so this // generally doesn't support multiple requests. - this._setActiveVerificationRequest(requestsInProgress[0]); + this._setActiveVerificationRequest(requestsInProgress[requestsInProgress.length - 1]); } this.fetchKeyInfo();