2019-11-07 19:40:22 +03:00
|
|
|
/*
|
2020-01-30 23:03:26 +03:00
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
2019-11-07 19:40: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from '../../../MatrixClientPeg';
|
2019-11-07 19:40:22 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2019-12-20 14:24:10 +03:00
|
|
|
import {getNameForEventRoom, userLabelForEventRoom}
|
2019-11-07 19:40:22 +03:00
|
|
|
from '../../../utils/KeyVerificationStateObserver';
|
|
|
|
|
|
|
|
export default class MKeyVerificationConclusion extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2019-12-20 14:24:10 +03:00
|
|
|
const request = this.props.mxEvent.verificationRequest;
|
|
|
|
if (request) {
|
|
|
|
request.on("change", this._onRequestChanged);
|
2019-11-07 19:40:22 +03:00
|
|
|
}
|
2020-02-04 14:25:19 +03:00
|
|
|
MatrixClientPeg.get().on("userTrustStatusChanged", this._onTrustChanged);
|
2019-11-07 19:40:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2019-12-20 14:24:10 +03:00
|
|
|
const request = this.props.mxEvent.verificationRequest;
|
|
|
|
if (request) {
|
|
|
|
request.off("change", this._onRequestChanged);
|
2019-11-07 19:40:22 +03:00
|
|
|
}
|
2020-02-05 02:13:55 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
if (cli) {
|
|
|
|
cli.removeListener("userTrustStatusChanged", this._onTrustChanged);
|
|
|
|
}
|
2019-11-07 19:40:22 +03:00
|
|
|
}
|
|
|
|
|
2019-12-20 14:24:10 +03:00
|
|
|
_onRequestChanged = () => {
|
|
|
|
this.forceUpdate();
|
|
|
|
};
|
2019-11-07 19:40:22 +03:00
|
|
|
|
2020-02-04 14:25:19 +03:00
|
|
|
_onTrustChanged = (userId, status) => {
|
|
|
|
const { mxEvent } = this.props;
|
|
|
|
const request = mxEvent.verificationRequest;
|
|
|
|
if (!request || request.otherUserId !== userId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.forceUpdate();
|
|
|
|
};
|
|
|
|
|
2020-01-03 15:40:20 +03:00
|
|
|
_shouldRender(mxEvent, request) {
|
|
|
|
// normally should not happen
|
|
|
|
if (!request) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// .cancel event that was sent after the verification finished, ignore
|
|
|
|
if (mxEvent.getType() === "m.key.verification.cancel" && !request.cancelled) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// .done event that was sent after the verification cancelled, ignore
|
|
|
|
if (mxEvent.getType() === "m.key.verification.done" && !request.done) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// request hasn't concluded yet
|
|
|
|
if (request.pending) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-01-31 13:37:40 +03:00
|
|
|
|
|
|
|
// User isn't actually verified
|
|
|
|
if (!MatrixClientPeg.get()
|
2020-02-04 14:25:19 +03:00
|
|
|
.checkUserTrust(request.otherUserId)
|
2020-01-31 13:37:40 +03:00
|
|
|
.isCrossSigningVerified()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-03 15:40:20 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-07 19:40:22 +03:00
|
|
|
render() {
|
|
|
|
const {mxEvent} = this.props;
|
2019-12-20 14:24:10 +03:00
|
|
|
const request = mxEvent.verificationRequest;
|
|
|
|
|
2020-01-03 15:40:20 +03:00
|
|
|
if (!this._shouldRender(mxEvent, request)) {
|
2019-12-20 23:31:36 +03:00
|
|
|
return null;
|
2019-12-20 14:24:10 +03:00
|
|
|
}
|
|
|
|
|
2019-12-20 23:31:36 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const myUserId = client.getUserId();
|
|
|
|
|
2019-11-07 19:40:22 +03:00
|
|
|
let title;
|
|
|
|
|
2019-12-20 14:24:10 +03:00
|
|
|
if (request.done) {
|
|
|
|
title = _t("You verified %(name)s", {name: getNameForEventRoom(request.otherUserId, mxEvent)});
|
|
|
|
} else if (request.cancelled) {
|
2020-01-03 15:40:20 +03:00
|
|
|
const userId = request.cancellingUserId;
|
|
|
|
if (userId === myUserId) {
|
2019-11-07 22:04:36 +03:00
|
|
|
title = _t("You cancelled verifying %(name)s",
|
2019-12-20 14:24:10 +03:00
|
|
|
{name: getNameForEventRoom(request.otherUserId, mxEvent)});
|
2020-01-03 15:40:20 +03:00
|
|
|
} else {
|
2019-11-07 22:04:36 +03:00
|
|
|
title = _t("%(name)s cancelled verifying",
|
2020-01-03 15:40:20 +03:00
|
|
|
{name: getNameForEventRoom(userId, mxEvent)});
|
2019-11-07 19:40:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (title) {
|
2020-01-24 13:57:57 +03:00
|
|
|
const subtitle = userLabelForEventRoom(request.otherUserId, mxEvent.getRoomId());
|
2020-01-30 23:03:26 +03:00
|
|
|
const classes = classNames("mx_EventTile_bubble", "mx_cryptoEvent", "mx_cryptoEvent_icon", {
|
|
|
|
mx_cryptoEvent_icon_verified: request.done,
|
2019-11-07 19:40:22 +03:00
|
|
|
});
|
|
|
|
return (<div className={classes}>
|
2020-01-30 23:03:26 +03:00
|
|
|
<div className="mx_cryptoEvent_title">{title}</div>
|
|
|
|
<div className="mx_cryptoEvent_subtitle">{subtitle}</div>
|
2019-11-07 19:40:22 +03:00
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MKeyVerificationConclusion.propTypes = {
|
|
|
|
/* the MatrixEvent to show */
|
|
|
|
mxEvent: PropTypes.object.isRequired,
|
|
|
|
};
|