Merge pull request #3941 from matrix-org/dbkr/dismiss_logged_out_device_toasts

Dismiss logged out device toasts
This commit is contained in:
David Baker 2020-01-27 10:25:20 +00:00 committed by GitHub
commit 1356b61276
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,8 +20,8 @@ import * as sdk from './index';
import { _t } from './languageHandler'; import { _t } from './languageHandler';
import ToastStore from './stores/ToastStore'; import ToastStore from './stores/ToastStore';
function toastKey(device) { function toastKey(deviceId) {
return 'newsession_' + device.deviceId; return 'newsession_' + deviceId;
} }
const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000; const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000;
@ -34,6 +34,8 @@ export default class DeviceListener {
} }
constructor() { constructor() {
// set of device IDs we're currently showing toasts for
this._activeNagToasts = new Set();
// device IDs for which the user has dismissed the verify toast ('Later') // device IDs for which the user has dismissed the verify toast ('Later')
this._dismissed = new Set(); this._dismissed = new Set();
// has the user dismissed any of the various nag toasts to setup encryption on this device? // has the user dismissed any of the various nag toasts to setup encryption on this device?
@ -145,22 +147,32 @@ export default class DeviceListener {
ToastStore.sharedInstance().dismissToast(THIS_DEVICE_TOAST_KEY); ToastStore.sharedInstance().dismissToast(THIS_DEVICE_TOAST_KEY);
} }
const newActiveToasts = new Set();
const devices = await cli.getStoredDevicesForUser(cli.getUserId()); const devices = await cli.getStoredDevicesForUser(cli.getUserId());
for (const device of devices) { for (const device of devices) {
if (device.deviceId == cli.deviceId) continue; if (device.deviceId == cli.deviceId) continue;
const deviceTrust = await cli.checkDeviceTrust(cli.getUserId(), device.deviceId); const deviceTrust = await cli.checkDeviceTrust(cli.getUserId(), device.deviceId);
if (deviceTrust.isCrossSigningVerified() || this._dismissed.has(device.deviceId)) { if (deviceTrust.isCrossSigningVerified() || this._dismissed.has(device.deviceId)) {
ToastStore.sharedInstance().dismissToast(toastKey(device)); ToastStore.sharedInstance().dismissToast(toastKey(device.deviceId));
} else { } else {
this._activeNagToasts.add(device.deviceId);
ToastStore.sharedInstance().addOrReplaceToast({ ToastStore.sharedInstance().addOrReplaceToast({
key: toastKey(device), key: toastKey(device.deviceId),
title: _t("New Session"), title: _t("New Session"),
icon: "verification_warning", icon: "verification_warning",
props: {deviceId: device.deviceId}, props: {deviceId: device.deviceId},
component: sdk.getComponent("toasts.NewSessionToast"), component: sdk.getComponent("toasts.NewSessionToast"),
}); });
newActiveToasts.add(device.deviceId);
} }
} }
// clear any other outstanding toasts (eg. logged out devices)
for (const deviceId of this._activeNagToasts) {
if (!newActiveToasts.has(deviceId)) ToastStore.sharedInstance().dismissToast(toastKey(deviceId));
}
this._activeNagToasts = newActiveToasts;
} }
} }