From 7169a8444959fe384504e99c5a0736408e9120ef Mon Sep 17 00:00:00 2001 From: David Baker Date: Sat, 25 Jan 2020 17:08:31 +0000 Subject: [PATCH] Dismiss toasts for logged out devices --- src/DeviceListener.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/DeviceListener.js b/src/DeviceListener.js index dc066eb7cb..3135e3d9a5 100644 --- a/src/DeviceListener.js +++ b/src/DeviceListener.js @@ -20,8 +20,8 @@ import * as sdk from './index'; import { _t } from './languageHandler'; import ToastStore from './stores/ToastStore'; -function toastKey(device) { - return 'newsession_' + device.deviceId; +function toastKey(deviceId) { + return 'newsession_' + deviceId; } const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000; @@ -34,6 +34,8 @@ export default class DeviceListener { } 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') this._dismissed = new Set(); // 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); } + const newActiveToasts = new Set(); + const devices = await cli.getStoredDevicesForUser(cli.getUserId()); for (const device of devices) { if (device.deviceId == cli.deviceId) continue; const deviceTrust = await cli.checkDeviceTrust(cli.getUserId(), device.deviceId); if (deviceTrust.isCrossSigningVerified() || this._dismissed.has(device.deviceId)) { - ToastStore.sharedInstance().dismissToast(toastKey(device)); + ToastStore.sharedInstance().dismissToast(toastKey(device.deviceId)); } else { + this._activeNagToasts.add(device.deviceId); ToastStore.sharedInstance().addOrReplaceToast({ - key: toastKey(device), + key: toastKey(device.deviceId), title: _t("New Session"), icon: "verification_warning", props: {deviceId: device.deviceId}, 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; } }