Merge pull request #4262 from matrix-org/dbkr/priority_toasts

Always display verification request toasts on top
pull/21833/head
David Baker 2020-03-24 09:51:35 +00:00 committed by GitHub
commit 99f12a695d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -1524,6 +1524,7 @@ export default createReactClass({
icon: "verification",
props: {request},
component: sdk.getComponent("toasts.VerificationRequestToast"),
priority: ToastStore.PRIORITY_REALTIME,
});
}
});

View File

@ -20,6 +20,9 @@ import EventEmitter from 'events';
* Holds the active toasts
*/
export default class ToastStore extends EventEmitter {
static PRIORITY_REALTIME = 1;
static PRIORITY_DEFAULT = 0;
static sharedInstance() {
if (!global.mx_ToastStore) global.mx_ToastStore = new ToastStore();
return global.mx_ToastStore;
@ -36,9 +39,16 @@ export default class ToastStore extends EventEmitter {
}
addOrReplaceToast(newToast) {
if (newToast.priority === undefined) newToast.priority = ToastStore.PRIORITY_DEFAULT;
const oldIndex = this._toasts.findIndex(t => t.key === newToast.key);
if (oldIndex === -1) {
// we only have two priorities so just push realtime ones onto the front
if (newToast.priority) {
this._toasts.unshift(newToast);
} else {
this._toasts.push(newToast);
}
} else {
this._toasts[oldIndex] = newToast;
}