Dismiss toasts for logged out devices

pull/21833/head
David Baker 2020-01-25 17:08:31 +00:00
parent 8c5fd5c77e
commit 7169a84449
1 changed files with 16 additions and 4 deletions

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 ID's 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;
} }
} }