Merge pull request #4538 from matrix-org/dbkr/wait_for_user_verified_rel

Wait for user to be verified in e2e setup
pull/21833/head
David Baker 2020-05-01 11:41:13 +01:00 committed by GitHub
commit df7c32187b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -78,6 +78,8 @@ export default class DeviceListener {
this._dismissedThisDeviceToast = false;
this._keyBackupInfo = null;
this._keyBackupFetchedAt = null;
this._ourDeviceIdsAtStart = null;
this._displayingToastsForDeviceIds = new Set();
}
/**

View File

@ -17,6 +17,7 @@ limitations under the License.
import EventEmitter from 'events';
import { MatrixClientPeg } from '../MatrixClientPeg';
import { accessSecretStorage, AccessCancelledError } from '../CrossSigningManager';
import { PHASE_DONE as VERIF_PHASE_DONE } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
export const PHASE_INTRO = 0;
export const PHASE_BUSY = 1;
@ -39,6 +40,7 @@ export class SetupEncryptionStore extends EventEmitter {
this.verificationRequest = null;
this.backupInfo = null;
MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest);
MatrixClientPeg.get().on('userTrustStatusChanged', this._onUserTrustStatusChanged);
}
stop() {
@ -51,6 +53,7 @@ export class SetupEncryptionStore extends EventEmitter {
}
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("crypto.verification.request", this.onVerificationRequest);
MatrixClientPeg.get().removeListener('userTrustStatusChanged', this._onUserTrustStatusChanged);
}
}
@ -102,6 +105,15 @@ export class SetupEncryptionStore extends EventEmitter {
}
}
_onUserTrustStatusChanged = async (userId) => {
if (userId !== MatrixClientPeg.get().getUserId()) return;
const crossSigningReady = await MatrixClientPeg.get().isCrossSigningReady();
if (crossSigningReady) {
this.phase = PHASE_DONE;
this.emit("update");
}
}
onVerificationRequest = async (request) => {
if (request.otherUserId !== MatrixClientPeg.get().getUserId()) return;
@ -114,11 +126,20 @@ export class SetupEncryptionStore extends EventEmitter {
this.emit("update");
}
onVerificationRequestChange = () => {
onVerificationRequestChange = async () => {
if (this.verificationRequest.cancelled) {
this.verificationRequest.off("change", this.onVerificationRequestChange);
this.verificationRequest = null;
this.emit("update");
} else if (this.verificationRequest.phase === VERIF_PHASE_DONE) {
this.verificationRequest.off("change", this.onVerificationRequestChange);
this.verificationRequest = null;
// At this point, the verification has finished, we just need to wait for
// cross signing to be ready to use, so wait for the user trust status to
// change (or change to DONE if it's already ready).
const crossSigningReady = await MatrixClientPeg.get().isCrossSigningReady();
this.phase = crossSigningReady ? PHASE_DONE : PHASE_BUSY;
this.emit("update");
}
}