From 9e38c627913444f358939533c43fce2dc7754ebf Mon Sep 17 00:00:00 2001 From: David Baker Date: Sat, 25 Jan 2020 20:42:45 +0000 Subject: [PATCH 1/2] Show incoming verification requests in the 'complete security' phase If you click to verify your new sign in on another device, actually show the verification request on the 'complete security' screen. --- .../structures/auth/CompleteSecurity.js | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/components/structures/auth/CompleteSecurity.js b/src/components/structures/auth/CompleteSecurity.js index 89711fcb1d..ce938bd2f8 100644 --- a/src/components/structures/auth/CompleteSecurity.js +++ b/src/components/structures/auth/CompleteSecurity.js @@ -35,7 +35,18 @@ export default class CompleteSecurity extends React.Component { this.state = { phase: PHASE_INTRO, + verificationRequest: null, }; + MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest); + } + + componentWillUnmount() { + if (this.state.verificationRequest) { + this.state.verificationRequest.off("change", this.onVerificationRequestChange); + } + if (MatrixClientPeg.get()) { + MatrixClientPeg.get().removeListener("crypto.verification.request", this.onVerificationRequest); + } } onStartClick = async () => { @@ -55,6 +66,27 @@ export default class CompleteSecurity extends React.Component { } } + onVerificationRequest = (request) => { + if (request.otherUserId !== MatrixClientPeg.get().getUserId()) return; + + if (this.state.verificationRequest) { + this.state.verificationRequest.off("change", this.onVerificationRequestChange); + } + request.on("change", this.onVerificationRequestChange); + this.setState({ + verificationRequest: request, + }); + } + + onVerificationRequestChange = () => { + if (this.state.verificationRequest.cancelled) { + this.state.verificationRequest.off("change", this.onVerificationRequestChange); + this.setState({ + verificationRequest: null, + }); + } + } + onSkipClick = () => { this.setState({ phase: PHASE_CONFIRM_SKIP, @@ -87,7 +119,13 @@ export default class CompleteSecurity extends React.Component { let icon; let title; let body; - if (phase === PHASE_INTRO) { + + if (this.state.verificationRequest) { + const IncomingSasDialog = sdk.getComponent("views.dialogs.IncomingSasDialog"); + body = ; + } else if (phase === PHASE_INTRO) { icon = ; title = _t("Complete security"); body = ( From 11de92b9a90c6d847f6687d6c9808a24ca189fdd Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 27 Jan 2020 11:07:55 +0000 Subject: [PATCH 2/2] hopefully informative comment --- src/components/structures/auth/CompleteSecurity.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/structures/auth/CompleteSecurity.js b/src/components/structures/auth/CompleteSecurity.js index ce938bd2f8..206cdb743e 100644 --- a/src/components/structures/auth/CompleteSecurity.js +++ b/src/components/structures/auth/CompleteSecurity.js @@ -35,6 +35,9 @@ export default class CompleteSecurity extends React.Component { this.state = { phase: PHASE_INTRO, + // this serves dual purpose as the object for the request logic and + // the presence of it insidicating that we're in 'verify mode'. + // Because of the latter, it lives in the state. verificationRequest: null, }; MatrixClientPeg.get().on("crypto.verification.request", this.onVerificationRequest);