Make shields in UserInfo black if user isn't verified

pull/21833/head
David Baker 2020-01-30 15:59:03 +00:00
parent 767015d19d
commit 0956d00637
3 changed files with 58 additions and 33 deletions

View File

@ -256,6 +256,9 @@ limitations under the License.
.mx_UserInfo_expand { .mx_UserInfo_expand {
display: flex; display: flex;
margin-top: 11px; margin-top: 11px;
}
.mx_UserInfo_expand_verified {
color: $accent-color; color: $accent-color;
} }
} }

View File

@ -2,7 +2,7 @@
Copyright 2015, 2016 OpenMarket Ltd Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017, 2018 Vector Creations Ltd Copyright 2017, 2018 Vector Creations Ltd
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
Copyright 2019 The Matrix.org Foundation C.I.C. Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -67,7 +67,9 @@ export const getE2EStatus = (cli, userId, devices) => {
} }
const isMe = userId === cli.getUserId(); const isMe = userId === cli.getUserId();
const userVerified = cli.checkUserTrust(userId).isCrossSigningVerified(); const userVerified = cli.checkUserTrust(userId).isCrossSigningVerified();
const allDevicesVerified = devices.every(device => { if (!userVerified) return "normal";
const anyDeviceUnverified = devices.some(device => {
const { deviceId } = device; const { deviceId } = device;
// For your own devices, we use the stricter check of cross-signing // For your own devices, we use the stricter check of cross-signing
// verification to encourage everyone to trust their own devices via // verification to encourage everyone to trust their own devices via
@ -75,12 +77,9 @@ export const getE2EStatus = (cli, userId, devices) => {
// For other people's devices, the more general verified check that // For other people's devices, the more general verified check that
// includes locally verified devices can be used. // includes locally verified devices can be used.
const deviceTrust = cli.checkDeviceTrust(userId, deviceId); const deviceTrust = cli.checkDeviceTrust(userId, deviceId);
return isMe ? deviceTrust.isCrossSigningVerified() : deviceTrust.isVerified(); return isMe ? !deviceTrust.isCrossSigningVerified() : !deviceTrust.isVerified();
}); });
if (allDevicesVerified) { return anyDeviceUnverified ? "warning" : "verified";
return userVerified ? "verified" : "normal";
}
return "warning";
}; };
async function openDMForUser(matrixClient, userId) { async function openDMForUser(matrixClient, userId) {
@ -156,6 +155,7 @@ function DeviceItem({userId, device}) {
const cli = useContext(MatrixClientContext); const cli = useContext(MatrixClientContext);
const isMe = userId === cli.getUserId(); const isMe = userId === cli.getUserId();
const deviceTrust = cli.checkDeviceTrust(userId, device.deviceId); const deviceTrust = cli.checkDeviceTrust(userId, device.deviceId);
const userTrust = cli.checkUserTrust(userId);
// For your own devices, we use the stricter check of cross-signing // For your own devices, we use the stricter check of cross-signing
// verification to encourage everyone to trust their own devices via // verification to encourage everyone to trust their own devices via
// cross-signing so that other users can then safely trust you. // cross-signing so that other users can then safely trust you.
@ -170,8 +170,9 @@ function DeviceItem({userId, device}) {
mx_UserInfo_device_unverified: !isVerified, mx_UserInfo_device_unverified: !isVerified,
}); });
const iconClasses = classNames("mx_E2EIcon", { const iconClasses = classNames("mx_E2EIcon", {
mx_E2EIcon_normal: !userTrust.isVerified(),
mx_E2EIcon_verified: isVerified, mx_E2EIcon_verified: isVerified,
mx_E2EIcon_warning: !isVerified, mx_E2EIcon_warning: userTrust.isVerified() && !isVerified,
}); });
const onDeviceClick = () => { const onDeviceClick = () => {
@ -183,7 +184,8 @@ function DeviceItem({userId, device}) {
const deviceName = device.ambiguous ? const deviceName = device.ambiguous ?
(device.getDisplayName() ? device.getDisplayName() : "") + " (" + device.deviceId + ")" : (device.getDisplayName() ? device.getDisplayName() : "") + " (" + device.deviceId + ")" :
device.getDisplayName(); device.getDisplayName();
const trustedLabel = isVerified ? _t("Trusted") : _t("Not trusted"); let trustedLabel = null;
if (userTrust.isVerified()) trustedLabel = isVerified ? _t("Trusted") : _t("Not trusted");
return ( return (
<AccessibleButton <AccessibleButton
className={classes} className={classes}
@ -200,6 +202,7 @@ function DeviceItem({userId, device}) {
function DevicesSection({devices, userId, loading}) { function DevicesSection({devices, userId, loading}) {
const Spinner = sdk.getComponent("elements.Spinner"); const Spinner = sdk.getComponent("elements.Spinner");
const cli = useContext(MatrixClientContext); const cli = useContext(MatrixClientContext);
const userTrust = cli.checkUserTrust(userId);
const [isExpanded, setExpanded] = useState(false); const [isExpanded, setExpanded] = useState(false);
@ -213,38 +216,54 @@ function DevicesSection({devices, userId, loading}) {
const isMe = userId === cli.getUserId(); const isMe = userId === cli.getUserId();
const deviceTrusts = devices.map(d => cli.checkDeviceTrust(userId, d.deviceId)); const deviceTrusts = devices.map(d => cli.checkDeviceTrust(userId, d.deviceId));
let expandSectionDevices = [];
const unverifiedDevices = []; const unverifiedDevices = [];
const verifiedDevices = [];
for (let i = 0; i < devices.length; ++i) { let expandCountCaption;
const device = devices[i]; let expandHideCaption;
const deviceTrust = deviceTrusts[i]; let expandClasses = "mx_UserInfo_expand";
// For your own devices, we use the stricter check of cross-signing let expandIconClasses = "mx_E2EIcon";
// verification to encourage everyone to trust their own devices via
// cross-signing so that other users can then safely trust you.
// For other people's devices, the more general verified check that
// includes locally verified devices can be used.
const isVerified = (isMe && SettingsStore.isFeatureEnabled("feature_cross_signing")) ?
deviceTrust.isCrossSigningVerified() :
deviceTrust.isVerified();
if (isVerified) { if (userTrust.isVerified()) {
verifiedDevices.push(device); for (let i = 0; i < devices.length; ++i) {
} else { const device = devices[i];
unverifiedDevices.push(device); const deviceTrust = deviceTrusts[i];
// For your own devices, we use the stricter check of cross-signing
// verification to encourage everyone to trust their own devices via
// cross-signing so that other users can then safely trust you.
// For other people's devices, the more general verified check that
// includes locally verified devices can be used.
const isVerified = (isMe && SettingsStore.isFeatureEnabled("feature_cross_signing")) ?
deviceTrust.isCrossSigningVerified() :
deviceTrust.isVerified();
if (isVerified) {
expandSectionDevices.push(device);
} else {
unverifiedDevices.push(device);
}
} }
expandCountCaption = _t("%(count)s verified sessions", {count: expandSectionDevices.length});
expandHideCaption = _t("Hide verified sessions");
expandClasses += " mx_UserInfo_expand_verified";
expandIconClasses += " mx_E2EIcon_verified";
} else {
expandSectionDevices = devices;
expandCountCaption = _t("%(count)s sessions", {count: devices.length});
expandHideCaption = _t("Hide sessions");
expandIconClasses += " mx_E2EIcon_normal";
} }
let expandButton; let expandButton;
if (verifiedDevices.length) { if (expandSectionDevices.length) {
if (isExpanded) { if (isExpanded) {
expandButton = (<AccessibleButton className="mx_UserInfo_expand" onClick={() => setExpanded(false)}> expandButton = (<AccessibleButton className={expandClasses} onClick={() => setExpanded(false)}>
<div>{_t("Hide verified sessions")}</div> <div>{expandHideCaption}</div>
</AccessibleButton>); </AccessibleButton>);
} else { } else {
expandButton = (<AccessibleButton className="mx_UserInfo_expand" onClick={() => setExpanded(true)}> expandButton = (<AccessibleButton className={expandClasses} onClick={() => setExpanded(true)}>
<div className="mx_E2EIcon mx_E2EIcon_verified" /> <div className={expandIconClasses} />
<div>{_t("%(count)s verified sessions", {count: verifiedDevices.length})}</div> <div>{expandCountCaption}</div>
</AccessibleButton>); </AccessibleButton>);
} }
} }
@ -254,7 +273,7 @@ function DevicesSection({devices, userId, loading}) {
}); });
if (isExpanded) { if (isExpanded) {
const keyStart = unverifiedDevices.length; const keyStart = unverifiedDevices.length;
deviceList = deviceList.concat(verifiedDevices.map((device, i) => { deviceList = deviceList.concat(expandSectionDevices.map((device, i) => {
return (<DeviceItem key={i + keyStart} userId={userId} device={device} />); return (<DeviceItem key={i + keyStart} userId={userId} device={device} />);
})); }));
} }

View File

@ -1159,9 +1159,12 @@
"Files": "Files", "Files": "Files",
"Trusted": "Trusted", "Trusted": "Trusted",
"Not trusted": "Not trusted", "Not trusted": "Not trusted",
"Hide verified sessions": "Hide verified sessions",
"%(count)s verified sessions|other": "%(count)s verified sessions", "%(count)s verified sessions|other": "%(count)s verified sessions",
"%(count)s verified sessions|one": "1 verified session", "%(count)s verified sessions|one": "1 verified session",
"Hide verified sessions": "Hide verified sessions",
"%(count)s sessions|other": "%(count)s sessions",
"%(count)s sessions|one": "%(count)s session",
"Hide sessions": "Hide sessions",
"Direct message": "Direct message", "Direct message": "Direct message",
"Remove from community": "Remove from community", "Remove from community": "Remove from community",
"Disinvite this user from community?": "Disinvite this user from community?", "Disinvite this user from community?": "Disinvite this user from community?",