Merge pull request #4519 from matrix-org/dbkr/new_device_toast_more_important
Make new device toasts appear above review toasts
This commit is contained in:
commit
1bd1e25047
2 changed files with 16 additions and 8 deletions
|
@ -267,6 +267,7 @@ export default class DeviceListener {
|
||||||
key: OTHER_DEVICES_TOAST_KEY,
|
key: OTHER_DEVICES_TOAST_KEY,
|
||||||
title: _t("Review where you’re logged in"),
|
title: _t("Review where you’re logged in"),
|
||||||
icon: "verification_warning",
|
icon: "verification_warning",
|
||||||
|
priority: ToastStore.PRIORITY_LOW,
|
||||||
props: {
|
props: {
|
||||||
deviceIds: oldUnverifiedDeviceIds,
|
deviceIds: oldUnverifiedDeviceIds,
|
||||||
},
|
},
|
||||||
|
|
|
@ -20,8 +20,9 @@ import EventEmitter from 'events';
|
||||||
* Holds the active toasts
|
* Holds the active toasts
|
||||||
*/
|
*/
|
||||||
export default class ToastStore extends EventEmitter {
|
export default class ToastStore extends EventEmitter {
|
||||||
static PRIORITY_REALTIME = 1;
|
static PRIORITY_REALTIME = 0;
|
||||||
static PRIORITY_DEFAULT = 0;
|
static PRIORITY_DEFAULT = 1;
|
||||||
|
static PRIORITY_LOW = 2;
|
||||||
|
|
||||||
static sharedInstance() {
|
static sharedInstance() {
|
||||||
if (!global.mx_ToastStore) global.mx_ToastStore = new ToastStore();
|
if (!global.mx_ToastStore) global.mx_ToastStore = new ToastStore();
|
||||||
|
@ -38,17 +39,23 @@ export default class ToastStore extends EventEmitter {
|
||||||
this._toasts = [];
|
this._toasts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add or replace a toast
|
||||||
|
* If a toast with the same toastKey already exists, the given toast will replace it
|
||||||
|
* Toasts are always added underneath any toasts of the same priority, so existing
|
||||||
|
* toasts stay at the top unless a higher priority one arrives (better to not change the
|
||||||
|
* toast unless necessary).
|
||||||
|
*
|
||||||
|
* @param {boject} newToast The new toast
|
||||||
|
*/
|
||||||
addOrReplaceToast(newToast) {
|
addOrReplaceToast(newToast) {
|
||||||
if (newToast.priority === undefined) newToast.priority = ToastStore.PRIORITY_DEFAULT;
|
if (newToast.priority === undefined) newToast.priority = ToastStore.PRIORITY_DEFAULT;
|
||||||
|
|
||||||
const oldIndex = this._toasts.findIndex(t => t.key === newToast.key);
|
const oldIndex = this._toasts.findIndex(t => t.key === newToast.key);
|
||||||
if (oldIndex === -1) {
|
if (oldIndex === -1) {
|
||||||
// we only have two priorities so just push realtime ones onto the front
|
let newIndex = this._toasts.length;
|
||||||
if (newToast.priority) {
|
while (newIndex > 0 && this._toasts[newIndex - 1].priority > newToast.priority) --newIndex;
|
||||||
this._toasts.unshift(newToast);
|
this._toasts.splice(newIndex, 0, newToast);
|
||||||
} else {
|
|
||||||
this._toasts.push(newToast);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this._toasts[oldIndex] = newToast;
|
this._toasts[oldIndex] = newToast;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue