2019-02-01 15:39:25 +03:00
|
|
|
/*
|
|
|
|
Copyright 2019 New Vector Ltd
|
2020-01-23 17:38:17 +03:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2019-02-01 15:39:25 +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-24 13:13:03 +03:00
|
|
|
import React, {useState} from "react";
|
2020-01-23 16:00:17 +03:00
|
|
|
import PropTypes from "prop-types";
|
2019-02-01 15:39:25 +03:00
|
|
|
import classNames from 'classnames';
|
2020-01-23 16:00:17 +03:00
|
|
|
|
|
|
|
import {_t, _td} from '../../../languageHandler';
|
2020-01-24 13:13:03 +03:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
|
|
|
import Tooltip from "../elements/Tooltip";
|
2019-02-01 15:39:25 +03:00
|
|
|
|
2020-01-22 19:54:31 +03:00
|
|
|
export const E2E_STATE = {
|
|
|
|
VERIFIED: "verified",
|
|
|
|
WARNING: "warning",
|
|
|
|
UNKNOWN: "unknown",
|
|
|
|
NORMAL: "normal",
|
2020-06-19 04:57:33 +03:00
|
|
|
UNAUTHENTICATED: "unauthenticated",
|
2020-01-22 19:54:31 +03:00
|
|
|
};
|
|
|
|
|
2020-01-23 16:00:17 +03:00
|
|
|
const crossSigningUserTitles = {
|
2020-01-29 18:48:25 +03:00
|
|
|
[E2E_STATE.WARNING]: _td("This user has not verified all of their sessions."),
|
2020-01-31 17:06:55 +03:00
|
|
|
[E2E_STATE.NORMAL]: _td("You have not verified this user."),
|
2020-01-29 18:48:25 +03:00
|
|
|
[E2E_STATE.VERIFIED]: _td("You have verified this user. This user has verified all of their sessions."),
|
2020-01-23 16:00:17 +03:00
|
|
|
};
|
|
|
|
const crossSigningRoomTitles = {
|
2020-01-29 18:48:25 +03:00
|
|
|
[E2E_STATE.WARNING]: _td("Someone is using an unknown session"),
|
2020-01-23 17:38:17 +03:00
|
|
|
[E2E_STATE.NORMAL]: _td("This room is end-to-end encrypted"),
|
|
|
|
[E2E_STATE.VERIFIED]: _td("Everyone in this room is verified"),
|
2020-01-23 16:00:17 +03:00
|
|
|
};
|
2020-01-23 17:38:17 +03:00
|
|
|
|
2020-07-14 02:52:03 +03:00
|
|
|
const E2EIcon = ({isUser, status, className, size, onClick, hideTooltip, bordered}) => {
|
2020-01-24 13:13:03 +03:00
|
|
|
const [hover, setHover] = useState(false);
|
|
|
|
|
|
|
|
const classes = classNames({
|
2019-02-01 15:39:25 +03:00
|
|
|
mx_E2EIcon: true,
|
2020-07-14 02:52:03 +03:00
|
|
|
mx_E2EIcon_bordered: bordered,
|
2020-01-23 16:00:17 +03:00
|
|
|
mx_E2EIcon_warning: status === E2E_STATE.WARNING,
|
|
|
|
mx_E2EIcon_normal: status === E2E_STATE.NORMAL,
|
|
|
|
mx_E2EIcon_verified: status === E2E_STATE.VERIFIED,
|
2020-01-22 19:54:31 +03:00
|
|
|
}, className);
|
2019-12-13 20:57:26 +03:00
|
|
|
|
2020-01-23 16:00:17 +03:00
|
|
|
let e2eTitle;
|
2020-05-27 12:28:25 +03:00
|
|
|
if (isUser) {
|
2020-01-23 16:00:17 +03:00
|
|
|
e2eTitle = crossSigningUserTitles[status];
|
2020-05-27 12:28:25 +03:00
|
|
|
} else {
|
2020-01-23 16:00:17 +03:00
|
|
|
e2eTitle = crossSigningRoomTitles[status];
|
2019-02-01 15:39:25 +03:00
|
|
|
}
|
2019-11-12 18:25:38 +03:00
|
|
|
|
2020-01-24 13:13:03 +03:00
|
|
|
let style;
|
2020-01-23 16:00:17 +03:00
|
|
|
if (size) {
|
|
|
|
style = {width: `${size}px`, height: `${size}px`};
|
2019-11-12 18:25:38 +03:00
|
|
|
}
|
|
|
|
|
2020-01-24 13:13:03 +03:00
|
|
|
const onMouseOver = () => setHover(true);
|
2020-07-18 14:01:51 +03:00
|
|
|
const onMouseLeave = () => setHover(false);
|
2020-01-24 13:13:03 +03:00
|
|
|
|
|
|
|
let tip;
|
2020-02-13 16:47:39 +03:00
|
|
|
if (hover && !hideTooltip) {
|
2020-01-24 13:13:03 +03:00
|
|
|
tip = <Tooltip label={e2eTitle ? _t(e2eTitle) : ""} />;
|
|
|
|
}
|
|
|
|
|
2020-01-23 16:00:17 +03:00
|
|
|
if (onClick) {
|
2020-01-24 13:13:03 +03:00
|
|
|
return (
|
|
|
|
<AccessibleButton
|
|
|
|
onClick={onClick}
|
|
|
|
onMouseOver={onMouseOver}
|
2020-07-18 14:01:51 +03:00
|
|
|
onMouseLeave={onMouseLeave}
|
2020-01-24 13:13:03 +03:00
|
|
|
className={classes}
|
|
|
|
style={style}
|
|
|
|
>
|
|
|
|
{ tip }
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
2019-02-12 21:59:31 +03:00
|
|
|
}
|
2020-01-24 13:13:03 +03:00
|
|
|
|
2020-07-18 14:01:51 +03:00
|
|
|
return <div onMouseOver={onMouseOver} onMouseLeave={onMouseLeave} className={classes} style={style}>
|
2020-01-24 13:13:03 +03:00
|
|
|
{ tip }
|
|
|
|
</div>;
|
2020-01-23 16:00:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
E2EIcon.propTypes = {
|
|
|
|
isUser: PropTypes.bool,
|
|
|
|
status: PropTypes.oneOf(Object.values(E2E_STATE)),
|
|
|
|
className: PropTypes.string,
|
|
|
|
size: PropTypes.number,
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default E2EIcon;
|