2020-01-31 14:01:32 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
2020-01-31 14:01:32 +01:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-01-31 14:01:32 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2025-09-26 09:59:40 +01:00
|
|
|
import { VerificationPhase, VerificationRequestEvent, type VerificationRequest } from "matrix-js-sdk/src/crypto-api";
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type User } from "matrix-js-sdk/src/matrix";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2021-06-29 13:11:58 +01:00
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
2020-02-01 18:25:01 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2021-07-01 14:22:58 +01:00
|
|
|
import BaseDialog from "./BaseDialog";
|
|
|
|
|
import EncryptionPanel from "../right_panel/EncryptionPanel";
|
|
|
|
|
|
|
|
|
|
interface IProps {
|
2023-02-28 10:31:48 +00:00
|
|
|
verificationRequest?: VerificationRequest;
|
|
|
|
|
verificationRequestPromise?: Promise<VerificationRequest>;
|
2021-07-01 14:22:58 +01:00
|
|
|
onFinished: () => void;
|
2023-02-28 10:31:48 +00:00
|
|
|
member?: User;
|
2021-07-01 14:22:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
2025-09-26 09:59:40 +01:00
|
|
|
// The VerificationRequest that is ongoing. This can be replaced if a
|
|
|
|
|
// promise was supplied in the props and it completes.
|
2023-02-28 10:31:48 +00:00
|
|
|
verificationRequest?: VerificationRequest;
|
2025-09-26 09:59:40 +01:00
|
|
|
|
|
|
|
|
// What phase the VerificationRequest is at. This is part of
|
|
|
|
|
// verificationRequest but we have it as independent state because we need
|
|
|
|
|
// to update when it changes.
|
|
|
|
|
//
|
|
|
|
|
// We listen to the `Change` event on verificationRequest and update phase
|
|
|
|
|
// when that fires.
|
|
|
|
|
phase?: VerificationPhase;
|
2021-07-01 14:22:58 +01:00
|
|
|
}
|
2020-01-31 14:01:32 +01:00
|
|
|
|
2021-07-01 14:22:58 +01:00
|
|
|
export default class VerificationRequestDialog extends React.Component<IProps, IState> {
|
2023-02-13 11:39:16 +00:00
|
|
|
public constructor(props: IProps) {
|
2021-07-01 14:22:58 +01:00
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
verificationRequest: this.props.verificationRequest,
|
2025-09-26 09:59:40 +01:00
|
|
|
phase: this.props.verificationRequest?.phase,
|
2021-07-01 14:22:58 +01:00
|
|
|
};
|
2024-11-01 17:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public componentDidMount(): void {
|
2025-09-26 09:59:40 +01:00
|
|
|
// Listen to when the verificationRequest changes, so we can keep our
|
|
|
|
|
// phase up-to-date.
|
|
|
|
|
this.state.verificationRequest?.on(VerificationRequestEvent.Change, this.onRequestChange);
|
|
|
|
|
|
2023-02-28 10:31:48 +00:00
|
|
|
this.props.verificationRequestPromise?.then((r) => {
|
2025-09-26 09:59:40 +01:00
|
|
|
// The request promise completed, so we have a new request
|
|
|
|
|
|
|
|
|
|
// Stop listening to the old request (if we have one, which normally we won't)
|
|
|
|
|
this.state.verificationRequest?.off(VerificationRequestEvent.Change, this.onRequestChange);
|
|
|
|
|
|
|
|
|
|
// And start listening to the new one
|
|
|
|
|
r.on(VerificationRequestEvent.Change, this.onRequestChange);
|
|
|
|
|
|
|
|
|
|
this.setState({ verificationRequest: r, phase: r.phase });
|
2023-02-28 10:31:48 +00:00
|
|
|
});
|
2020-02-18 11:14:16 +01:00
|
|
|
}
|
|
|
|
|
|
2025-09-26 09:59:40 +01:00
|
|
|
public componentWillUnmount(): void {
|
|
|
|
|
// Stop listening for changes to the request when we close
|
|
|
|
|
this.state.verificationRequest?.off(VerificationRequestEvent.Change, this.onRequestChange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The verificationRequest changed, so we need to make sure we update our
|
|
|
|
|
* state to have the correct phase.
|
|
|
|
|
*
|
|
|
|
|
* Note: this is called when verificationRequest changes in some way, not
|
|
|
|
|
* when we replace verificationRequest with some new request.
|
|
|
|
|
*/
|
|
|
|
|
private readonly onRequestChange = (): void => {
|
|
|
|
|
this.setState((prevState) => ({
|
|
|
|
|
phase: prevState.verificationRequest?.phase,
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2020-04-02 17:12:10 +02:00
|
|
|
const request = this.state.verificationRequest;
|
2023-02-28 10:31:48 +00:00
|
|
|
const otherUserId = request?.otherUserId;
|
2023-06-15 08:46:19 +01:00
|
|
|
const member = this.props.member || (otherUserId ? MatrixClientPeg.safeGet().getUser(otherUserId) : null);
|
2025-09-26 09:59:40 +01:00
|
|
|
const title = this.dialogTitle(request);
|
2020-04-02 17:12:10 +02:00
|
|
|
|
2023-05-25 09:39:23 +01:00
|
|
|
if (!member) return null;
|
|
|
|
|
|
2021-04-27 17:23:27 +02:00
|
|
|
return (
|
|
|
|
|
<BaseDialog
|
|
|
|
|
className="mx_InfoDialog"
|
|
|
|
|
onFinished={this.props.onFinished}
|
|
|
|
|
contentId="mx_Dialog_content"
|
|
|
|
|
title={title}
|
|
|
|
|
hasCancel={true}
|
|
|
|
|
>
|
2020-02-01 18:25:01 +01:00
|
|
|
<EncryptionPanel
|
|
|
|
|
layout="dialog"
|
2025-09-25 09:08:16 +01:00
|
|
|
verificationRequest={this.state.verificationRequest}
|
2020-03-10 18:59:45 +01:00
|
|
|
verificationRequestPromise={this.props.verificationRequestPromise}
|
2020-02-01 18:25:01 +01:00
|
|
|
onClose={this.props.onFinished}
|
2020-03-10 18:59:45 +01:00
|
|
|
member={member}
|
2021-07-01 14:22:58 +01:00
|
|
|
isRoomEncrypted={false}
|
2020-02-01 18:25:01 +01:00
|
|
|
/>
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
);
|
2020-01-31 14:01:32 +01:00
|
|
|
}
|
2025-09-26 09:59:40 +01:00
|
|
|
|
|
|
|
|
private dialogTitle(request?: VerificationRequest): string {
|
|
|
|
|
if (request?.isSelfVerification) {
|
|
|
|
|
if (request.phase === VerificationPhase.Cancelled) {
|
|
|
|
|
return _t("encryption|verification|verification_dialog_title_failed");
|
|
|
|
|
} else {
|
|
|
|
|
return _t("encryption|verification|verification_dialog_title_device");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return _t("encryption|verification|verification_dialog_title_user");
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-31 14:01:32 +01:00
|
|
|
}
|