2020-01-31 16:01:32 +03:00
|
|
|
/*
|
2020-01-31 16:42:27 +03:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2020-01-31 16:01:32 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import {MatrixClientPeg} from '../../../MatrixClientPeg';
|
|
|
|
import * as sdk from '../../../index';
|
2020-02-01 20:25:01 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2020-01-31 16:01:32 +03:00
|
|
|
|
2020-01-31 19:15:52 +03:00
|
|
|
export default class VerificationRequestDialog extends React.Component {
|
2020-01-31 16:01:32 +03:00
|
|
|
static propTypes = {
|
2020-03-10 20:59:45 +03:00
|
|
|
verificationRequest: PropTypes.object,
|
|
|
|
verificationRequestPromise: PropTypes.object,
|
2020-01-31 16:01:32 +03:00
|
|
|
onFinished: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2020-02-18 13:14:16 +03:00
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
this.onFinished = this.onFinished.bind(this);
|
2020-04-02 18:12:10 +03:00
|
|
|
this.state = {};
|
|
|
|
if (this.props.verificationRequest) {
|
|
|
|
this.state.verificationRequest = this.props.verificationRequest;
|
|
|
|
} else if (this.props.verificationRequestPromise) {
|
|
|
|
this.props.verificationRequestPromise.then(r => {
|
|
|
|
this.setState({verificationRequest: r});
|
|
|
|
});
|
|
|
|
}
|
2020-02-18 13:14:16 +03:00
|
|
|
}
|
|
|
|
|
2020-01-31 16:01:32 +03:00
|
|
|
render() {
|
2020-02-01 20:25:01 +03:00
|
|
|
const BaseDialog = sdk.getComponent("views.dialogs.BaseDialog");
|
2020-01-31 16:01:32 +03:00
|
|
|
const EncryptionPanel = sdk.getComponent("views.right_panel.EncryptionPanel");
|
2020-04-02 18:12:10 +03:00
|
|
|
const request = this.state.verificationRequest;
|
|
|
|
const otherUserId = request && request.otherUserId;
|
2020-03-10 20:59:45 +03:00
|
|
|
const member = this.props.member ||
|
2020-04-02 18:12:10 +03:00
|
|
|
otherUserId && MatrixClientPeg.get().getUser(otherUserId);
|
|
|
|
const title = request && request.isSelfVerification ?
|
2020-04-16 15:28:12 +03:00
|
|
|
_t("Verify other session") : _t("Verification Request");
|
2020-04-02 18:12:10 +03:00
|
|
|
|
2020-02-18 13:14:16 +03:00
|
|
|
return <BaseDialog className="mx_InfoDialog" onFinished={this.onFinished}
|
2020-02-01 20:25:01 +03:00
|
|
|
contentId="mx_Dialog_content"
|
2020-04-02 18:12:10 +03:00
|
|
|
title={title}
|
2020-02-01 20:25:01 +03:00
|
|
|
hasCancel={true}
|
|
|
|
>
|
|
|
|
<EncryptionPanel
|
|
|
|
layout="dialog"
|
|
|
|
verificationRequest={this.props.verificationRequest}
|
2020-03-10 20:59:45 +03:00
|
|
|
verificationRequestPromise={this.props.verificationRequestPromise}
|
2020-02-01 20:25:01 +03:00
|
|
|
onClose={this.props.onFinished}
|
2020-03-10 20:59:45 +03:00
|
|
|
member={member}
|
2020-02-01 20:25:01 +03:00
|
|
|
/>
|
|
|
|
</BaseDialog>;
|
2020-01-31 16:01:32 +03:00
|
|
|
}
|
2020-02-18 13:14:16 +03:00
|
|
|
|
2020-03-10 20:59:45 +03:00
|
|
|
async onFinished() {
|
2020-02-18 13:14:16 +03:00
|
|
|
this.props.onFinished();
|
2020-03-10 20:59:45 +03:00
|
|
|
let request = this.props.verificationRequest;
|
|
|
|
if (!request && this.props.verificationRequestPromise) {
|
|
|
|
request = await this.props.verificationRequestPromise;
|
|
|
|
}
|
|
|
|
request.cancel();
|
2020-02-18 13:14:16 +03:00
|
|
|
}
|
2020-01-31 16:01:32 +03:00
|
|
|
}
|