Merge pull request #4762 from matrix-org/dbkr/fix_verification_race

Look for existing verification requests after login
pull/21833/head
David Baker 2020-06-19 17:06:02 +01:00 committed by GitHub
commit 87ab0f9830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 10 deletions

View File

@ -41,6 +41,17 @@ export class SetupEncryptionStore extends EventEmitter {
this.backupInfo = null; this.backupInfo = null;
MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest); MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest);
MatrixClientPeg.get().on('userTrustStatusChanged', this._onUserTrustStatusChanged); MatrixClientPeg.get().on('userTrustStatusChanged', this._onUserTrustStatusChanged);
const cli = MatrixClientPeg.get();
const requestsInProgress = cli.getVerificationRequestsToDeviceInProgress(cli.getUserId());
if (requestsInProgress.length) {
// 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[requestsInProgress.length - 1]);
}
this.fetchKeyInfo();
} }
stop() { stop() {
@ -114,16 +125,8 @@ export class SetupEncryptionStore extends EventEmitter {
} }
} }
onVerificationRequest = async (request) => { onVerificationRequest = (request) => {
if (request.otherUserId !== MatrixClientPeg.get().getUserId()) return; this._setActiveVerificationRequest(request);
if (this.verificationRequest) {
this.verificationRequest.off("change", this.onVerificationRequestChange);
}
this.verificationRequest = request;
await request.accept();
request.on("change", this.onVerificationRequestChange);
this.emit("update");
} }
onVerificationRequestChange = async () => { onVerificationRequestChange = async () => {
@ -164,4 +167,16 @@ export class SetupEncryptionStore extends EventEmitter {
// async - ask other clients for keys, if necessary // async - ask other clients for keys, if necessary
MatrixClientPeg.get()._crypto.cancelAndResendAllOutgoingKeyRequests(); 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");
}
} }