2019-02-01 13:39:25 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2019 New Vector Ltd
|
2020-01-23 14:38:17 +00:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2019-02-01 13:39:25 +01: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.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-13 15:07:20 +00:00
|
|
|
import React, { CSSProperties, useState } from "react";
|
2019-02-01 13:39:25 +01:00
|
|
|
import classNames from "classnames";
|
2020-01-23 13:00:17 +00:00
|
|
|
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t, _td } from "../../../languageHandler";
|
2020-01-24 10:13:03 +00:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2022-10-06 22:27:28 -04:00
|
|
|
import Tooltip, { Alignment } from "../elements/Tooltip";
|
2021-09-20 13:23:02 +02:00
|
|
|
import { E2EStatus } from "../../../utils/ShieldUtils";
|
2019-02-01 13:39:25 +01:00
|
|
|
|
2021-09-21 08:18:49 +02:00
|
|
|
export enum E2EState {
|
2021-09-20 17:10:22 +02:00
|
|
|
Verified = "verified",
|
|
|
|
|
Warning = "warning",
|
|
|
|
|
Unknown = "unknown",
|
|
|
|
|
Normal = "normal",
|
|
|
|
|
Unauthenticated = "unauthenticated",
|
2021-09-20 13:23:02 +02:00
|
|
|
}
|
2020-01-22 16:54:31 +00:00
|
|
|
|
2021-09-21 08:18:49 +02:00
|
|
|
const crossSigningUserTitles: { [key in E2EState]?: string } = {
|
|
|
|
|
[E2EState.Warning]: _td("This user has not verified all of their sessions."),
|
|
|
|
|
[E2EState.Normal]: _td("You have not verified this user."),
|
|
|
|
|
[E2EState.Verified]: _td("You have verified this user. This user has verified all of their sessions."),
|
2020-01-23 13:00:17 +00:00
|
|
|
};
|
2021-09-21 08:18:49 +02:00
|
|
|
const crossSigningRoomTitles: { [key in E2EState]?: string } = {
|
|
|
|
|
[E2EState.Warning]: _td("Someone is using an unknown session"),
|
|
|
|
|
[E2EState.Normal]: _td("This room is end-to-end encrypted"),
|
|
|
|
|
[E2EState.Verified]: _td("Everyone in this room is verified"),
|
2020-01-23 13:00:17 +00:00
|
|
|
};
|
2020-01-23 14:38:17 +00:00
|
|
|
|
2021-09-20 13:23:02 +02:00
|
|
|
interface IProps {
|
|
|
|
|
isUser?: boolean;
|
2023-03-13 15:07:20 +00:00
|
|
|
status?: E2EState | E2EStatus;
|
2021-09-20 13:23:02 +02:00
|
|
|
className?: string;
|
|
|
|
|
size?: number;
|
|
|
|
|
onClick?: () => void;
|
|
|
|
|
hideTooltip?: boolean;
|
2022-10-06 22:27:28 -04:00
|
|
|
tooltipAlignment?: Alignment;
|
2021-09-20 13:23:02 +02:00
|
|
|
bordered?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 22:27:28 -04:00
|
|
|
const E2EIcon: React.FC<IProps> = ({
|
|
|
|
|
isUser,
|
|
|
|
|
status,
|
|
|
|
|
className,
|
|
|
|
|
size,
|
|
|
|
|
onClick,
|
|
|
|
|
hideTooltip,
|
|
|
|
|
tooltipAlignment,
|
|
|
|
|
bordered,
|
|
|
|
|
}) => {
|
2020-01-24 10:13:03 +00:00
|
|
|
const [hover, setHover] = useState(false);
|
|
|
|
|
|
|
|
|
|
const classes = classNames(
|
|
|
|
|
{
|
2019-02-01 13:39:25 +01:00
|
|
|
mx_E2EIcon: true,
|
2020-07-14 00:52:03 +01:00
|
|
|
mx_E2EIcon_bordered: bordered,
|
2021-09-21 08:18:49 +02:00
|
|
|
mx_E2EIcon_warning: status === E2EState.Warning,
|
|
|
|
|
mx_E2EIcon_normal: status === E2EState.Normal,
|
|
|
|
|
mx_E2EIcon_verified: status === E2EState.Verified,
|
2020-01-22 16:54:31 +00:00
|
|
|
},
|
|
|
|
|
className,
|
|
|
|
|
);
|
2019-12-13 17:57:26 +00:00
|
|
|
|
2023-03-10 14:55:06 +00:00
|
|
|
let e2eTitle: string | undefined;
|
2023-03-13 15:07:20 +00:00
|
|
|
if (status) {
|
|
|
|
|
if (isUser) {
|
|
|
|
|
e2eTitle = crossSigningUserTitles[status];
|
|
|
|
|
} else {
|
|
|
|
|
e2eTitle = crossSigningRoomTitles[status];
|
|
|
|
|
}
|
2019-02-01 13:39:25 +01:00
|
|
|
}
|
2019-11-12 16:25:38 +01:00
|
|
|
|
2023-03-13 15:07:20 +00:00
|
|
|
let style: CSSProperties | undefined;
|
2020-01-23 13:00:17 +00:00
|
|
|
if (size) {
|
2021-06-29 13:11:58 +01:00
|
|
|
style = { width: `${size}px`, height: `${size}px` };
|
2019-11-12 16:25:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const onMouseOver = (): void => setHover(true);
|
|
|
|
|
const onMouseLeave = (): void => setHover(false);
|
2020-01-24 10:13:03 +00:00
|
|
|
|
2023-03-13 15:07:20 +00:00
|
|
|
let tip: JSX.Element | undefined;
|
2020-02-13 13:47:39 +00:00
|
|
|
if (hover && !hideTooltip) {
|
2022-10-06 22:27:28 -04:00
|
|
|
tip = <Tooltip label={e2eTitle ? _t(e2eTitle) : ""} alignment={tooltipAlignment} />;
|
2019-02-12 19:59:31 +01:00
|
|
|
}
|
2020-01-24 10:13:03 +00:00
|
|
|
|
|
|
|
|
if (onClick) {
|
|
|
|
|
return (
|
|
|
|
|
<AccessibleButton
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
onMouseOver={onMouseOver}
|
2020-07-18 12:01:51 +01:00
|
|
|
onMouseLeave={onMouseLeave}
|
2020-01-24 10:13:03 +00:00
|
|
|
className={classes}
|
|
|
|
|
style={style}
|
|
|
|
|
>
|
|
|
|
|
{tip}
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 12:01:51 +01:00
|
|
|
return (
|
|
|
|
|
<div onMouseOver={onMouseOver} onMouseLeave={onMouseLeave} className={classes} style={style}>
|
2020-01-24 10:13:03 +00:00
|
|
|
{tip}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2020-01-23 13:00:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default E2EIcon;
|