Merge pull request #3942 from matrix-org/dbkr/show_incoming_verifications_in_complete_security

Show incoming verification requests in the 'complete security' phase
This commit is contained in:
David Baker
2020-01-27 11:17:16 +00:00
committed by GitHub
@@ -35,7 +35,21 @@ export default class CompleteSecurity extends React.Component {
this.state = { this.state = {
phase: PHASE_INTRO, 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);
}
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 () => { onStartClick = async () => {
@@ -55,6 +69,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 = () => { onSkipClick = () => {
this.setState({ this.setState({
phase: PHASE_CONFIRM_SKIP, phase: PHASE_CONFIRM_SKIP,
@@ -87,7 +122,13 @@ export default class CompleteSecurity extends React.Component {
let icon; let icon;
let title; let title;
let body; let body;
if (phase === PHASE_INTRO) {
if (this.state.verificationRequest) {
const IncomingSasDialog = sdk.getComponent("views.dialogs.IncomingSasDialog");
body = <IncomingSasDialog verifier={this.state.verificationRequest.verifier}
onFinished={this.props.onFinished}
/>;
} else if (phase === PHASE_INTRO) {
icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning"></span>; icon = <span className="mx_CompleteSecurity_headerIcon mx_E2EIcon_warning"></span>;
title = _t("Complete security"); title = _t("Complete security");
body = ( body = (