element-web/src/components/views/rooms/E2EIcon.js

95 lines
3.2 KiB
JavaScript
Raw Normal View History

/*
Copyright 2019 New Vector Ltd
Copyright 2020 The Matrix.org Foundation C.I.C.
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";
2020-01-23 16:00:17 +03:00
import PropTypes from "prop-types";
import classNames from 'classnames';
2020-01-23 16:00:17 +03:00
import {_t, _td} from '../../../languageHandler';
import AccessibleButton from '../elements/AccessibleButton';
import {useFeatureEnabled} from "../../../hooks/useSettings";
export const E2E_STATE = {
VERIFIED: "verified",
WARNING: "warning",
UNKNOWN: "unknown",
NORMAL: "normal",
};
2020-01-23 16:00:17 +03:00
const crossSigningUserTitles = {
[E2E_STATE.WARNING]: _td("This user has not verified all of their devices."),
[E2E_STATE.NORMAL]: _td("You have not verified this user. This user has verified all of their devices."),
[E2E_STATE.VERIFIED]: _td("You have verified this user. This user has verified all of their devices."),
};
const crossSigningRoomTitles = {
[E2E_STATE.WARNING]: _td("Someone is using an unknown device"),
[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 16:00:17 +03:00
const legacyUserTitles = {
[E2E_STATE.WARNING]: _td("Some devices for this user are not trusted"),
[E2E_STATE.VERIFIED]: _td("All devices for this user are trusted"),
};
const legacyRoomTitles = {
[E2E_STATE.WARNING]: _td("Some devices in this encrypted room are not trusted"),
[E2E_STATE.VERIFIED]: _td("All devices in this encrypted room are trusted"),
};
const E2EIcon = ({isUser, status, className, size, onClick}) => {
const e2eIconClasses = classNames({
mx_E2EIcon: true,
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,
}, className);
2020-01-23 16:00:17 +03:00
let e2eTitle;
const crossSigning = useFeatureEnabled("feature_cross_signing");
if (crossSigning && isUser) {
2020-01-23 16:00:17 +03:00
e2eTitle = crossSigningUserTitles[status];
} else if (crossSigning && !isUser) {
2020-01-23 16:00:17 +03:00
e2eTitle = crossSigningRoomTitles[status];
} else if (!crossSigning && isUser) {
2020-01-23 16:00:17 +03:00
e2eTitle = legacyUserTitles[status];
} else if (!crossSigning && !isUser) {
2020-01-23 16:00:17 +03:00
e2eTitle = legacyRoomTitles[status];
}
2019-11-12 18:25:38 +03:00
let style = null;
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-23 16:00:17 +03:00
const icon = (<div className={e2eIconClasses} style={style} title={e2eTitle ? _t(e2eTitle) : undefined} />);
if (onClick) {
return (<AccessibleButton onClick={onClick}>{ icon }</AccessibleButton>);
} else {
return icon;
}
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;