Use per-message string substitutions in key backup panel

Including unused substitutions triggers console logs, so change the key backup
panel to only substitute what's actually used in each message.

Fixes https://github.com/vector-im/riot-web/issues/8047.
This commit is contained in:
J. Ryan Stinnett 2019-01-07 17:59:57 -06:00
parent e5f74957cb
commit 02a83a7c2b

View file

@ -155,46 +155,44 @@ export default class KeyBackupPanel extends React.Component {
let backupSigStatuses = this.state.backupSigStatus.sigs.map((sig, i) => { let backupSigStatuses = this.state.backupSigStatus.sigs.map((sig, i) => {
const deviceName = sig.device.getDisplayName() || sig.device.deviceId; const deviceName = sig.device.getDisplayName() || sig.device.deviceId;
const sigStatusSubstitutions = { const validity = sub =>
validity: sub => <span className={sig.valid ? 'mx_KeyBackupPanel_sigValid' : 'mx_KeyBackupPanel_sigInvalid'}>
<span className={sig.valid ? 'mx_KeyBackupPanel_sigValid' : 'mx_KeyBackupPanel_sigInvalid'}> {sub}
{sub} </span>;
</span>, const verify = sub =>
verify: sub => <span className={sig.device.isVerified() ? 'mx_KeyBackupPanel_deviceVerified' : 'mx_KeyBackupPanel_deviceNotVerified'}>
<span className={sig.device.isVerified() ? 'mx_KeyBackupPanel_deviceVerified' : 'mx_KeyBackupPanel_deviceNotVerified'}> {sub}
{sub} </span>;
</span>, const device = sub => <span className="mx_KeyBackupPanel_deviceName">{deviceName}</span>;
device: sub => <span className="mx_KeyBackupPanel_deviceName">{deviceName}</span>,
};
let sigStatus; let sigStatus;
if (sig.device.getFingerprint() === MatrixClientPeg.get().getDeviceEd25519Key()) { if (sig.device.getFingerprint() === MatrixClientPeg.get().getDeviceEd25519Key()) {
sigStatus = _t( sigStatus = _t(
"Backup has a <validity>valid</validity> signature from this device", "Backup has a <validity>valid</validity> signature from this device",
{}, sigStatusSubstitutions, {}, { validity },
); );
} else if (sig.valid && sig.device.isVerified()) { } else if (sig.valid && sig.device.isVerified()) {
sigStatus = _t( sigStatus = _t(
"Backup has a <validity>valid</validity> signature from " + "Backup has a <validity>valid</validity> signature from " +
"<verify>verified</verify> device <device></device>", "<verify>verified</verify> device <device></device>",
{}, sigStatusSubstitutions, {}, { validity, verify, device },
); );
} else if (sig.valid && !sig.device.isVerified()) { } else if (sig.valid && !sig.device.isVerified()) {
sigStatus = _t( sigStatus = _t(
"Backup has a <validity>valid</validity> signature from " + "Backup has a <validity>valid</validity> signature from " +
"<verify>unverified</verify> device <device></device>", "<verify>unverified</verify> device <device></device>",
{}, sigStatusSubstitutions, {}, { validity, verify, device },
); );
} else if (!sig.valid && sig.device.isVerified()) { } else if (!sig.valid && sig.device.isVerified()) {
sigStatus = _t( sigStatus = _t(
"Backup has an <validity>invalid</validity> signature from " + "Backup has an <validity>invalid</validity> signature from " +
"<verify>verified</verify> device <device></device>", "<verify>verified</verify> device <device></device>",
{}, sigStatusSubstitutions, {}, { validity, verify, device },
); );
} else if (!sig.valid && !sig.device.isVerified()) { } else if (!sig.valid && !sig.device.isVerified()) {
sigStatus = _t( sigStatus = _t(
"Backup has an <validity>invalid</validity> signature from " + "Backup has an <validity>invalid</validity> signature from " +
"<verify>unverified</verify> device <device></device>", "<verify>unverified</verify> device <device></device>",
{}, sigStatusSubstitutions, {}, { validity, verify, device },
); );
} }