2019-12-16 20:16:22 +03:00
|
|
|
|
/*
|
2020-01-24 19:16:46 +03:00
|
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
2019-12-16 20:16:22 +03:00
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-01-29 10:53:45 +03:00
|
|
|
|
import React from "react";
|
2020-01-24 19:16:46 +03:00
|
|
|
|
|
2020-05-12 13:05:30 +03:00
|
|
|
|
import {MatrixClientPeg} from "../../../MatrixClientPeg";
|
2020-01-17 17:50:27 +03:00
|
|
|
|
import * as sdk from '../../../index';
|
2020-01-16 23:23:32 +03:00
|
|
|
|
import {verificationMethods} from 'matrix-js-sdk/src/crypto';
|
2020-02-14 15:48:18 +03:00
|
|
|
|
import {SCAN_QR_CODE_METHOD} from "matrix-js-sdk/src/crypto/verification/QRCode";
|
2020-07-18 21:21:46 +03:00
|
|
|
|
import {VerificationRequest} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
|
|
|
|
import {RoomMember} from "matrix-js-sdk/src/models/room-member";
|
|
|
|
|
import {ReciprocateQRCode} from "matrix-js-sdk/src/crypto/verification/QRCode";
|
|
|
|
|
import {SAS} from "matrix-js-sdk/src/crypto/verification/SAS";
|
2020-02-14 15:48:18 +03:00
|
|
|
|
|
2020-01-18 05:53:33 +03:00
|
|
|
|
import VerificationQRCode from "../elements/crypto/VerificationQRCode";
|
2020-01-24 19:16:46 +03:00
|
|
|
|
import {_t} from "../../../languageHandler";
|
2020-07-10 21:07:11 +03:00
|
|
|
|
import SdkConfig from "../../../SdkConfig";
|
2020-01-24 19:16:46 +03:00
|
|
|
|
import E2EIcon from "../rooms/E2EIcon";
|
2020-01-28 14:13:09 +03:00
|
|
|
|
import {
|
2020-01-29 10:53:45 +03:00
|
|
|
|
PHASE_UNSENT,
|
|
|
|
|
PHASE_REQUESTED,
|
2020-01-28 14:13:09 +03:00
|
|
|
|
PHASE_READY,
|
|
|
|
|
PHASE_DONE,
|
|
|
|
|
PHASE_STARTED,
|
2020-03-31 16:46:11 +03:00
|
|
|
|
PHASE_CANCELLED,
|
2020-01-28 14:13:09 +03:00
|
|
|
|
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
|
|
|
|
import Spinner from "../elements/Spinner";
|
2019-12-16 20:16:22 +03:00
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
// XXX: Should be defined in matrix-js-sdk
|
|
|
|
|
enum VerificationPhase {
|
|
|
|
|
PHASE_UNSENT,
|
|
|
|
|
PHASE_REQUESTED,
|
|
|
|
|
PHASE_READY,
|
|
|
|
|
PHASE_DONE,
|
|
|
|
|
PHASE_STARTED,
|
|
|
|
|
PHASE_CANCELLED,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
|
layout: string;
|
|
|
|
|
request: VerificationRequest;
|
|
|
|
|
member: RoomMember;
|
|
|
|
|
phase: VerificationPhase;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
isRoomEncrypted: boolean;
|
|
|
|
|
inDialog: boolean;
|
|
|
|
|
key: any;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
|
sasEvent?: SAS;
|
|
|
|
|
emojiButtonClicked?: boolean;
|
|
|
|
|
reciprocateButtonClicked?: boolean;
|
|
|
|
|
reciprocateQREvent?: ReciprocateQRCode;
|
|
|
|
|
}
|
2020-01-29 10:53:45 +03:00
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
export default class VerificationPanel extends React.PureComponent<IProps, IState> {
|
|
|
|
|
private hasVerifier: boolean;
|
|
|
|
|
|
|
|
|
|
constructor(props: IProps) {
|
2019-12-16 20:16:22 +03:00
|
|
|
|
super(props);
|
2020-03-31 16:46:11 +03:00
|
|
|
|
this.state = {};
|
2020-07-18 21:21:46 +03:00
|
|
|
|
this.hasVerifier = false;
|
2019-12-16 20:16:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 16:46:41 +03:00
|
|
|
|
renderQRPhase() {
|
2020-02-14 15:48:18 +03:00
|
|
|
|
const {member, request} = this.props;
|
2020-07-18 21:21:46 +03:00
|
|
|
|
const showSAS: boolean = request.otherPartySupportsMethod(verificationMethods.SAS);
|
|
|
|
|
const showQR: boolean = request.otherPartySupportsMethod(SCAN_QR_CODE_METHOD);
|
2020-01-24 19:16:46 +03:00
|
|
|
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
2020-07-10 21:07:11 +03:00
|
|
|
|
const brand = SdkConfig.get().brand;
|
2020-01-24 19:41:43 +03:00
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
const noCommonMethodError: JSX.Element = !showSAS && !showQR ?
|
2020-07-10 21:07:11 +03:00
|
|
|
|
<p>{_t(
|
|
|
|
|
"The session you are trying to verify doesn't support scanning a " +
|
|
|
|
|
"QR code or emoji verification, which is what %(brand)s supports. Try " +
|
|
|
|
|
"with a different client.",
|
|
|
|
|
{ brand },
|
|
|
|
|
)}</p> :
|
2020-02-14 15:48:18 +03:00
|
|
|
|
null;
|
|
|
|
|
|
2020-01-31 18:04:44 +03:00
|
|
|
|
if (this.props.layout === 'dialog') {
|
|
|
|
|
// HACK: This is a terrible idea.
|
2020-07-18 21:22:41 +03:00
|
|
|
|
let qrBlockDialog: JSX.Element;
|
|
|
|
|
let sasBlockDialog: JSX.Element;
|
2020-02-14 15:48:18 +03:00
|
|
|
|
if (showQR) {
|
2020-07-18 21:22:41 +03:00
|
|
|
|
qrBlockDialog =
|
2020-02-14 15:48:18 +03:00
|
|
|
|
<div className='mx_VerificationPanel_QRPhase_startOption'>
|
|
|
|
|
<p>{_t("Scan this unique code")}</p>
|
2020-03-31 16:46:11 +03:00
|
|
|
|
<VerificationQRCode qrCodeData={request.qrCodeData} />
|
2020-02-14 15:48:18 +03:00
|
|
|
|
</div>;
|
2020-01-31 18:04:44 +03:00
|
|
|
|
}
|
2020-02-14 15:48:18 +03:00
|
|
|
|
if (showSAS) {
|
2020-07-18 21:22:41 +03:00
|
|
|
|
sasBlockDialog =
|
2020-02-14 15:48:18 +03:00
|
|
|
|
<div className='mx_VerificationPanel_QRPhase_startOption'>
|
|
|
|
|
<p>{_t("Compare unique emoji")}</p>
|
|
|
|
|
<span className='mx_VerificationPanel_QRPhase_helpText'>{_t("Compare a unique set of emoji if you don't have a camera on either device")}</span>
|
2020-07-18 21:21:46 +03:00
|
|
|
|
<AccessibleButton disabled={this.state.emojiButtonClicked} onClick={this.startSAS} kind='primary'>
|
2020-02-14 15:48:18 +03:00
|
|
|
|
{_t("Start")}
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>;
|
|
|
|
|
}
|
2020-07-18 21:22:41 +03:00
|
|
|
|
const or = qrBlockDialog && sasBlockDialog ?
|
2020-02-14 15:48:18 +03:00
|
|
|
|
<div className='mx_VerificationPanel_QRPhase_betweenText'>{_t("or")}</div> : null;
|
2020-01-31 18:04:44 +03:00
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
{_t("Verify this session by completing one of the following:")}
|
2020-02-10 16:20:54 +03:00
|
|
|
|
<div className='mx_VerificationPanel_QRPhase_startOptions'>
|
2020-07-18 21:22:41 +03:00
|
|
|
|
{qrBlockDialog}
|
2020-02-14 15:48:18 +03:00
|
|
|
|
{or}
|
2020-07-18 21:22:41 +03:00
|
|
|
|
{sasBlockDialog}
|
2020-02-14 15:48:18 +03:00
|
|
|
|
{noCommonMethodError}
|
2020-01-31 18:04:44 +03:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
let qrBlock: JSX.Element;
|
2020-03-31 16:46:11 +03:00
|
|
|
|
if (showQR) {
|
2020-02-14 15:48:18 +03:00
|
|
|
|
qrBlock = <div className="mx_UserInfo_container">
|
2020-02-10 16:44:20 +03:00
|
|
|
|
<h3>{_t("Verify by scanning")}</h3>
|
2020-01-27 20:17:05 +03:00
|
|
|
|
<p>{_t("Ask %(displayName)s to scan your code:", {
|
2020-01-24 19:16:46 +03:00
|
|
|
|
displayName: member.displayName || member.name || member.userId,
|
|
|
|
|
})}</p>
|
2020-01-24 19:41:43 +03:00
|
|
|
|
|
2020-01-27 20:17:05 +03:00
|
|
|
|
<div className="mx_VerificationPanel_qrCode">
|
2020-03-31 16:46:11 +03:00
|
|
|
|
<VerificationQRCode qrCodeData={request.qrCodeData} />
|
2020-01-27 20:17:05 +03:00
|
|
|
|
</div>
|
2020-02-14 15:48:18 +03:00
|
|
|
|
</div>;
|
|
|
|
|
}
|
2020-01-24 19:16:46 +03:00
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
let sasBlock: JSX.Element;
|
2020-02-14 15:48:18 +03:00
|
|
|
|
if (showSAS) {
|
2020-03-31 16:46:41 +03:00
|
|
|
|
const disabled = this.state.emojiButtonClicked;
|
2020-03-31 16:46:11 +03:00
|
|
|
|
const sasLabel = showQR ?
|
2020-02-14 15:48:18 +03:00
|
|
|
|
_t("If you can't scan the code above, verify by comparing unique emoji.") :
|
|
|
|
|
_t("Verify by comparing unique emoji.");
|
2020-04-17 23:31:33 +03:00
|
|
|
|
|
|
|
|
|
// Note: mx_VerificationPanel_verifyByEmojiButton is for the end-to-end tests
|
2020-02-14 15:48:18 +03:00
|
|
|
|
sasBlock = <div className="mx_UserInfo_container">
|
2020-02-10 16:44:20 +03:00
|
|
|
|
<h3>{_t("Verify by emoji")}</h3>
|
2020-02-14 15:48:18 +03:00
|
|
|
|
<p>{sasLabel}</p>
|
2020-04-17 23:31:33 +03:00
|
|
|
|
<AccessibleButton
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
kind="primary"
|
|
|
|
|
className="mx_UserInfo_wideButton mx_VerificationPanel_verifyByEmojiButton"
|
2020-07-18 21:21:46 +03:00
|
|
|
|
onClick={this.startSAS}
|
2020-04-17 23:31:33 +03:00
|
|
|
|
>
|
2020-03-31 16:46:41 +03:00
|
|
|
|
{_t("Verify by emoji")}
|
|
|
|
|
</AccessibleButton>
|
2020-02-14 15:48:18 +03:00
|
|
|
|
</div>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const noCommonMethodBlock = noCommonMethodError ?
|
|
|
|
|
<div className="mx_UserInfo_container">{noCommonMethodError}</div> :
|
|
|
|
|
null;
|
|
|
|
|
|
|
|
|
|
// TODO: add way to open camera to scan a QR code
|
|
|
|
|
return <React.Fragment>
|
|
|
|
|
{qrBlock}
|
|
|
|
|
{sasBlock}
|
|
|
|
|
{noCommonMethodBlock}
|
2020-01-24 19:16:46 +03:00
|
|
|
|
</React.Fragment>;
|
2019-12-20 23:30:47 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
private onReciprocateYesClick = () => {
|
2020-04-02 14:00:45 +03:00
|
|
|
|
this.setState({reciprocateButtonClicked: true});
|
|
|
|
|
this.state.reciprocateQREvent.confirm();
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
private onReciprocateNoClick = () => {
|
2020-04-02 14:00:45 +03:00
|
|
|
|
this.setState({reciprocateButtonClicked: true});
|
|
|
|
|
this.state.reciprocateQREvent.cancel();
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
private getDevice() {
|
2020-05-12 13:05:30 +03:00
|
|
|
|
const deviceId = this.props.request && this.props.request.channel.deviceId;
|
|
|
|
|
return MatrixClientPeg.get().getStoredDevice(MatrixClientPeg.get().getUserId(), deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 16:46:41 +03:00
|
|
|
|
renderQRReciprocatePhase() {
|
2020-04-02 18:12:10 +03:00
|
|
|
|
const {member, request} = this.props;
|
2020-04-02 17:42:39 +03:00
|
|
|
|
let Button;
|
2020-04-02 17:44:42 +03:00
|
|
|
|
// a bit of a hack, but the FormButton should only be used in the right panel
|
|
|
|
|
// they should probably just be the same component with a css class applied to it?
|
2020-04-02 17:42:39 +03:00
|
|
|
|
if (this.props.inDialog) {
|
|
|
|
|
Button = sdk.getComponent("elements.AccessibleButton");
|
|
|
|
|
} else {
|
|
|
|
|
Button = sdk.getComponent("elements.FormButton");
|
|
|
|
|
}
|
2020-04-02 18:12:10 +03:00
|
|
|
|
const description = request.isSelfVerification ?
|
2020-04-02 17:42:39 +03:00
|
|
|
|
_t("Almost there! Is your other session showing the same shield?") :
|
|
|
|
|
_t("Almost there! Is %(displayName)s showing the same shield?", {
|
|
|
|
|
displayName: member.displayName || member.name || member.userId,
|
|
|
|
|
});
|
2020-07-18 21:21:46 +03:00
|
|
|
|
let body: JSX.Element;
|
2020-03-31 16:46:41 +03:00
|
|
|
|
if (this.state.reciprocateQREvent) {
|
|
|
|
|
// riot web doesn't support scanning yet, so assume here we're the client being scanned.
|
2020-04-02 17:44:42 +03:00
|
|
|
|
//
|
|
|
|
|
// we're passing both a label and a child string to Button as
|
|
|
|
|
// FormButton and AccessibleButton expect this differently
|
2020-03-31 16:46:41 +03:00
|
|
|
|
body = <React.Fragment>
|
2020-04-02 17:42:39 +03:00
|
|
|
|
<p>{description}</p>
|
2020-03-31 16:46:41 +03:00
|
|
|
|
<E2EIcon isUser={true} status="verified" size={128} hideTooltip={true} />
|
2020-04-02 14:00:45 +03:00
|
|
|
|
<div className="mx_VerificationPanel_reciprocateButtons">
|
2020-04-02 17:42:39 +03:00
|
|
|
|
<Button
|
2020-04-02 14:00:45 +03:00
|
|
|
|
label={_t("No")} kind="danger"
|
|
|
|
|
disabled={this.state.reciprocateButtonClicked}
|
2020-07-18 21:21:46 +03:00
|
|
|
|
onClick={this.onReciprocateNoClick}>{_t("No")}</Button>
|
2020-04-02 17:42:39 +03:00
|
|
|
|
<Button
|
|
|
|
|
label={_t("Yes")} kind="primary"
|
2020-04-02 14:00:45 +03:00
|
|
|
|
disabled={this.state.reciprocateButtonClicked}
|
2020-07-18 21:21:46 +03:00
|
|
|
|
onClick={this.onReciprocateYesClick}>{_t("Yes")}</Button>
|
2020-04-02 14:00:45 +03:00
|
|
|
|
</div>
|
2020-03-31 16:46:41 +03:00
|
|
|
|
</React.Fragment>;
|
|
|
|
|
} else {
|
2020-04-02 14:00:45 +03:00
|
|
|
|
body = <p><Spinner /></p>;
|
2020-03-31 16:46:41 +03:00
|
|
|
|
}
|
2020-04-02 13:54:14 +03:00
|
|
|
|
return <div className="mx_UserInfo_container mx_VerificationPanel_reciprocate_section">
|
2020-03-31 16:46:41 +03:00
|
|
|
|
<h3>{_t("Verify by scanning")}</h3>
|
|
|
|
|
{ body }
|
|
|
|
|
</div>;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-24 19:16:46 +03:00
|
|
|
|
renderVerifiedPhase() {
|
2020-04-03 18:04:29 +03:00
|
|
|
|
const {member, request} = this.props;
|
2020-01-24 19:16:46 +03:00
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
let text: string;
|
2020-04-03 18:04:29 +03:00
|
|
|
|
if (!request.isSelfVerification) {
|
|
|
|
|
if (this.props.isRoomEncrypted) {
|
|
|
|
|
text = _t("Verify all users in a room to ensure it's secure.");
|
|
|
|
|
} else {
|
|
|
|
|
text = _t("In encrypted rooms, verify all users to ensure it’s secure.");
|
|
|
|
|
}
|
2020-03-26 01:38:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
let description: string;
|
2020-05-12 13:05:30 +03:00
|
|
|
|
if (request.isSelfVerification) {
|
2020-07-18 21:21:46 +03:00
|
|
|
|
const device = this.getDevice();
|
2020-05-12 13:05:30 +03:00
|
|
|
|
if (!device) {
|
2020-05-12 13:14:05 +03:00
|
|
|
|
// This can happen if the device is logged out while we're still showing verification
|
|
|
|
|
// UI for it.
|
2020-05-12 13:05:30 +03:00
|
|
|
|
console.warn("Verified device we don't know about: " + this.props.request.channel.deviceId);
|
2020-05-12 14:42:16 +03:00
|
|
|
|
description = _t("You've successfully verified your device!");
|
|
|
|
|
} else {
|
|
|
|
|
description = _t("You've successfully verified %(deviceName)s (%(deviceId)s)!", {
|
|
|
|
|
deviceName: device ? device.getDisplayName() : '',
|
|
|
|
|
deviceId: this.props.request.channel.deviceId,
|
|
|
|
|
});
|
2020-05-12 13:05:30 +03:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
description = _t("You've successfully verified %(displayName)s!", {
|
2020-04-03 18:03:37 +03:00
|
|
|
|
displayName: member.displayName || member.name || member.userId,
|
|
|
|
|
});
|
2020-05-12 13:05:30 +03:00
|
|
|
|
}
|
2020-04-03 18:03:37 +03:00
|
|
|
|
|
2020-05-12 13:05:30 +03:00
|
|
|
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
2020-01-24 19:16:46 +03:00
|
|
|
|
return (
|
|
|
|
|
<div className="mx_UserInfo_container mx_VerificationPanel_verified_section">
|
2020-03-26 01:38:11 +03:00
|
|
|
|
<h3>{_t("Verified")}</h3>
|
2020-04-03 18:03:37 +03:00
|
|
|
|
<p>{description}</p>
|
2020-02-13 17:15:08 +03:00
|
|
|
|
<E2EIcon isUser={true} status="verified" size={128} hideTooltip={true} />
|
2020-04-03 18:04:29 +03:00
|
|
|
|
{ text ? <p>{ text }</p> : null }
|
2020-01-29 17:11:50 +03:00
|
|
|
|
<AccessibleButton kind="primary" className="mx_UserInfo_wideButton" onClick={this.props.onClose}>
|
2020-01-24 19:16:46 +03:00
|
|
|
|
{_t("Got it")}
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 14:13:09 +03:00
|
|
|
|
renderCancelledPhase() {
|
2020-01-24 19:16:46 +03:00
|
|
|
|
const {member, request} = this.props;
|
|
|
|
|
|
2020-01-28 14:13:09 +03:00
|
|
|
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
let startAgainInstruction: string;
|
2020-04-03 18:04:29 +03:00
|
|
|
|
if (request.isSelfVerification) {
|
|
|
|
|
startAgainInstruction = _t("Start verification again from the notification.");
|
|
|
|
|
} else {
|
|
|
|
|
startAgainInstruction = _t("Start verification again from their profile.");
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
let text: string;
|
2020-01-28 14:13:09 +03:00
|
|
|
|
if (request.cancellationCode === "m.timeout") {
|
2020-04-03 18:04:29 +03:00
|
|
|
|
text = _t("Verification timed out.") + ` ${startAgainInstruction}`;
|
2020-01-28 14:13:09 +03:00
|
|
|
|
} else if (request.cancellingUserId === request.otherUserId) {
|
2020-04-03 18:04:29 +03:00
|
|
|
|
if (request.isSelfVerification) {
|
|
|
|
|
text = _t("You cancelled verification on your other session.");
|
|
|
|
|
} else {
|
|
|
|
|
text = _t("%(displayName)s cancelled verification.", {
|
|
|
|
|
displayName: member.displayName || member.name || member.userId,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
text = `${text} ${startAgainInstruction}`;
|
2020-01-28 14:13:09 +03:00
|
|
|
|
} else {
|
2020-04-03 18:04:29 +03:00
|
|
|
|
text = _t("You cancelled verification.") + ` ${startAgainInstruction}`;
|
2020-01-28 14:13:09 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_UserInfo_container">
|
2020-03-26 01:38:11 +03:00
|
|
|
|
<h3>{_t("Verification cancelled")}</h3>
|
2020-01-28 14:13:09 +03:00
|
|
|
|
<p>{ text }</p>
|
|
|
|
|
|
2020-01-29 17:11:50 +03:00
|
|
|
|
<AccessibleButton kind="primary" className="mx_UserInfo_wideButton" onClick={this.props.onClose}>
|
2020-01-28 14:13:09 +03:00
|
|
|
|
{_t("Got it")}
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2020-03-31 16:46:41 +03:00
|
|
|
|
const {member, phase, request} = this.props;
|
2020-01-28 14:13:09 +03:00
|
|
|
|
|
2020-01-24 19:16:46 +03:00
|
|
|
|
const displayName = member.displayName || member.name || member.userId;
|
2019-12-16 20:16:22 +03:00
|
|
|
|
|
2020-01-29 11:00:32 +03:00
|
|
|
|
switch (phase) {
|
2020-01-28 14:13:09 +03:00
|
|
|
|
case PHASE_READY:
|
|
|
|
|
return this.renderQRPhase();
|
|
|
|
|
case PHASE_STARTED:
|
2020-03-31 16:46:41 +03:00
|
|
|
|
switch (request.chosenMethod) {
|
|
|
|
|
case verificationMethods.RECIPROCATE_QR_CODE:
|
|
|
|
|
return this.renderQRReciprocatePhase();
|
|
|
|
|
case verificationMethods.SAS: {
|
|
|
|
|
const VerificationShowSas = sdk.getComponent('views.verification.VerificationShowSas');
|
|
|
|
|
const emojis = this.state.sasEvent ?
|
|
|
|
|
<VerificationShowSas
|
|
|
|
|
displayName={displayName}
|
2020-07-18 21:21:46 +03:00
|
|
|
|
device={this.getDevice()}
|
2020-03-31 16:46:41 +03:00
|
|
|
|
sas={this.state.sasEvent.sas}
|
2020-07-18 21:21:46 +03:00
|
|
|
|
onCancel={this.onSasMismatchesClick}
|
|
|
|
|
onDone={this.onSasMatchesClick}
|
2020-03-31 16:46:41 +03:00
|
|
|
|
inDialog={this.props.inDialog}
|
2020-04-02 19:28:14 +03:00
|
|
|
|
isSelf={request.isSelfVerification}
|
2020-03-31 16:46:41 +03:00
|
|
|
|
/> : <Spinner />;
|
|
|
|
|
return <div className="mx_UserInfo_container">
|
|
|
|
|
<h3>{_t("Compare emoji")}</h3>
|
|
|
|
|
{ emojis }
|
|
|
|
|
</div>;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
2020-01-28 14:13:09 +03:00
|
|
|
|
}
|
|
|
|
|
case PHASE_DONE:
|
|
|
|
|
return this.renderVerifiedPhase();
|
|
|
|
|
case PHASE_CANCELLED:
|
|
|
|
|
return this.renderCancelledPhase();
|
2019-12-16 20:16:22 +03:00
|
|
|
|
}
|
2020-01-29 11:08:52 +03:00
|
|
|
|
console.error("VerificationPanel unhandled phase:", phase);
|
2020-01-24 19:16:46 +03:00
|
|
|
|
return null;
|
2019-12-16 20:16:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
private startSAS = async () => {
|
2020-02-02 12:48:02 +03:00
|
|
|
|
this.setState({emojiButtonClicked: true});
|
2019-12-16 20:16:22 +03:00
|
|
|
|
const verifier = this.props.request.beginKeyVerification(verificationMethods.SAS);
|
|
|
|
|
try {
|
2019-12-18 20:26:54 +03:00
|
|
|
|
await verifier.verify();
|
2019-12-19 19:08:53 +03:00
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err);
|
2019-12-16 20:16:22 +03:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
private onSasMatchesClick = () => {
|
2019-12-16 20:16:22 +03:00
|
|
|
|
this.state.sasEvent.confirm();
|
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
private onSasMismatchesClick = () => {
|
2020-01-28 14:13:09 +03:00
|
|
|
|
this.state.sasEvent.mismatch();
|
2019-12-16 20:16:22 +03:00
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
private updateVerifierState = () => {
|
2020-02-24 15:48:41 +03:00
|
|
|
|
const {request} = this.props;
|
2020-04-02 12:27:00 +03:00
|
|
|
|
const {sasEvent, reciprocateQREvent} = request.verifier;
|
2020-07-18 21:21:46 +03:00
|
|
|
|
request.verifier.off('show_sas', this.updateVerifierState);
|
|
|
|
|
request.verifier.off('show_reciprocate_qr', this.updateVerifierState);
|
2020-03-31 16:46:41 +03:00
|
|
|
|
this.setState({sasEvent, reciprocateQREvent});
|
2019-12-16 20:16:22 +03:00
|
|
|
|
};
|
|
|
|
|
|
2020-07-18 21:21:46 +03:00
|
|
|
|
private onRequestChange = async () => {
|
2019-12-18 20:26:54 +03:00
|
|
|
|
const {request} = this.props;
|
2020-07-18 21:21:46 +03:00
|
|
|
|
const hadVerifier = this.hasVerifier;
|
|
|
|
|
this.hasVerifier = !!request.verifier;
|
|
|
|
|
if (!hadVerifier && this.hasVerifier) {
|
|
|
|
|
request.verifier.on('show_sas', this.updateVerifierState);
|
|
|
|
|
request.verifier.on('show_reciprocate_qr', this.updateVerifierState);
|
2019-12-18 20:26:54 +03:00
|
|
|
|
try {
|
2020-07-18 21:21:46 +03:00
|
|
|
|
// on the requester side, this is also awaited in startSAS,
|
2019-12-19 19:28:23 +03:00
|
|
|
|
// but that's ok as verify should return the same promise.
|
|
|
|
|
await request.verifier.verify();
|
2019-12-18 20:26:54 +03:00
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("error verify", err);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-16 20:16:22 +03:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-02-13 16:32:33 +03:00
|
|
|
|
const {request} = this.props;
|
2020-07-18 21:21:46 +03:00
|
|
|
|
request.on("change", this.onRequestChange);
|
2020-02-13 16:32:33 +03:00
|
|
|
|
if (request.verifier) {
|
2020-04-02 12:27:00 +03:00
|
|
|
|
const {sasEvent, reciprocateQREvent} = request.verifier;
|
2020-03-31 16:46:41 +03:00
|
|
|
|
this.setState({sasEvent, reciprocateQREvent});
|
2020-02-13 16:32:33 +03:00
|
|
|
|
}
|
2020-07-18 21:21:46 +03:00
|
|
|
|
this.onRequestChange();
|
2019-12-16 20:16:22 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2020-02-24 15:48:41 +03:00
|
|
|
|
const {request} = this.props;
|
|
|
|
|
if (request.verifier) {
|
2020-07-18 21:21:46 +03:00
|
|
|
|
request.verifier.off('show_sas', this.updateVerifierState);
|
|
|
|
|
request.verifier.off('show_reciprocate_qr', this.updateVerifierState);
|
2020-02-24 15:48:41 +03:00
|
|
|
|
}
|
2020-07-18 21:21:46 +03:00
|
|
|
|
request.off("change", this.onRequestChange);
|
2019-12-16 20:16:22 +03:00
|
|
|
|
}
|
|
|
|
|
}
|