2019-02-01 15:39:25 +03:00
|
|
|
/*
|
|
|
|
Copyright 2019 New Vector Ltd
|
|
|
|
|
|
|
|
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-22 19:54:31 +03:00
|
|
|
import React from "react";
|
2019-02-01 15:39:25 +03:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { _t } from '../../../languageHandler';
|
2019-02-12 20:43:28 +03:00
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
2019-12-13 20:57:26 +03:00
|
|
|
import SettingsStore from '../../../settings/SettingsStore';
|
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",
|
|
|
|
};
|
|
|
|
|
2019-02-01 15:39:25 +03:00
|
|
|
export default function(props) {
|
2020-01-22 19:54:31 +03:00
|
|
|
const { isUser, status, className } = props;
|
|
|
|
const isNormal = status === E2E_STATE.NORMAL;
|
|
|
|
const isWarning = status === E2E_STATE.WARNING;
|
|
|
|
const isVerified = status === E2E_STATE.VERIFIED;
|
2019-02-01 15:39:25 +03:00
|
|
|
const e2eIconClasses = classNames({
|
|
|
|
mx_E2EIcon: true,
|
|
|
|
mx_E2EIcon_warning: isWarning,
|
2019-12-13 20:57:26 +03:00
|
|
|
mx_E2EIcon_normal: isNormal,
|
2019-02-01 15:39:25 +03:00
|
|
|
mx_E2EIcon_verified: isVerified,
|
2020-01-22 19:54:31 +03:00
|
|
|
}, className);
|
2019-02-01 15:39:25 +03:00
|
|
|
let e2eTitle;
|
2019-12-13 20:57:26 +03:00
|
|
|
|
|
|
|
const crossSigning = SettingsStore.isFeatureEnabled("feature_cross_signing");
|
|
|
|
if (crossSigning && isUser) {
|
|
|
|
if (isWarning) {
|
|
|
|
e2eTitle = _t(
|
|
|
|
"This user has not verified all of their devices.",
|
|
|
|
);
|
|
|
|
} else if (isNormal) {
|
|
|
|
e2eTitle = _t(
|
|
|
|
"You have not verified this user. " +
|
|
|
|
"This user has verified all of their devices.",
|
|
|
|
);
|
|
|
|
} else if (isVerified) {
|
|
|
|
e2eTitle = _t(
|
|
|
|
"You have verified this user. " +
|
|
|
|
"This user has verified all of their devices.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if (crossSigning && !isUser) {
|
|
|
|
if (isWarning) {
|
|
|
|
e2eTitle = _t(
|
|
|
|
"Some users in this encrypted room are not verified by you or " +
|
|
|
|
"they have not verified their own devices.",
|
|
|
|
);
|
|
|
|
} else if (isVerified) {
|
|
|
|
e2eTitle = _t(
|
|
|
|
"All users in this encrypted room are verified by you and " +
|
|
|
|
"they have verified their own devices.",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else if (!crossSigning && isUser) {
|
|
|
|
if (isWarning) {
|
|
|
|
e2eTitle = _t("Some devices for this user are not trusted");
|
|
|
|
} else if (isVerified) {
|
|
|
|
e2eTitle = _t("All devices for this user are trusted");
|
|
|
|
}
|
|
|
|
} else if (!crossSigning && !isUser) {
|
|
|
|
if (isWarning) {
|
|
|
|
e2eTitle = _t("Some devices in this encrypted room are not trusted");
|
|
|
|
} else if (isVerified) {
|
|
|
|
e2eTitle = _t("All devices in this encrypted room are trusted");
|
|
|
|
}
|
2019-02-01 15:39:25 +03:00
|
|
|
}
|
2019-11-12 18:25:38 +03:00
|
|
|
|
|
|
|
let style = null;
|
|
|
|
if (props.size) {
|
|
|
|
style = {width: `${props.size}px`, height: `${props.size}px`};
|
|
|
|
}
|
|
|
|
|
|
|
|
const icon = (<div className={e2eIconClasses} style={style} title={e2eTitle} />);
|
2019-02-12 21:59:31 +03:00
|
|
|
if (props.onClick) {
|
|
|
|
return (<AccessibleButton onClick={props.onClick}>{ icon }</AccessibleButton>);
|
|
|
|
} else {
|
|
|
|
return icon;
|
|
|
|
}
|
2019-02-01 15:39:25 +03:00
|
|
|
}
|