element-web/src/components/views/right_panel/EncryptionPanel.js

66 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-12-10 19:53:51 +03:00
/*
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
2019-12-10 19:53:51 +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';
2019-12-16 20:16:22 +03:00
import EncryptionInfo from "./EncryptionInfo";
import VerificationPanel from "./VerificationPanel";
import {MatrixClientPeg} from "../../../MatrixClientPeg";
import {ensureDMExists} from "../../../createRoom";
import {UserInfoPane} from "./UserInfo";
import {_t} from "../../../languageHandler";
2019-12-10 19:53:51 +03:00
export default class EncryptionPanel extends React.PureComponent {
constructor(props) {
super(props);
this.state = {};
}
2019-12-10 19:53:51 +03:00
render() {
let content;
2019-12-16 20:16:22 +03:00
const request = this.props.verificationRequest || this.state.verificationRequest;
const {member} = this.props;
2019-12-10 19:53:51 +03:00
if (request) {
content = <VerificationPanel request={request} key={request.channel.transactionId} />;
2019-12-16 20:16:22 +03:00
} else if (member) {
content = <EncryptionInfo onStartVerification={this._onStartVerification} member={member} />;
} else {
content = <p>Not a member nor request, not sure what to render</p>;
2019-12-10 19:53:51 +03:00
}
return (
<UserInfoPane className="mx_UserInfo_smallAvatar" member={member} onClose={this.props.onClose} e2eStatus="">
<div className="mx_UserInfo_container">
<h3>{_t("Encryption")}</h3>
<div>
<p>{_t("Messages in this room are end-to-end encrypted.")}</p>
<p>{_t("Your messages are secured and only you and the recipient have the unique keys to unlock them.")}</p>
</div>
</div>
{ content }
</UserInfoPane>
);
2019-12-10 19:53:51 +03:00
}
2019-12-16 20:16:22 +03:00
_onStartVerification = async () => {
const client = MatrixClientPeg.get();
const {member} = this.props;
const roomId = await ensureDMExists(client, member.userId);
const verificationRequest = await client.requestVerificationDM(member.userId, roomId);
2019-12-16 20:16:22 +03:00
this.setState({verificationRequest});
};
2019-12-10 19:53:51 +03:00
}