mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 12:28:50 +03:00
Merge pull request #3941 from matrix-org/dbkr/dismiss_logged_out_device_toasts
Dismiss logged out device toasts
This commit is contained in:
commit
1356b61276
1 changed files with 16 additions and 4 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue