From eae690f3efdfa7177eca3356b507cc515e3e5159 Mon Sep 17 00:00:00 2001
From: David Baker <dave@matrix.org>
Date: Mon, 23 Mar 2020 15:52:59 +0000
Subject: [PATCH] Always display verification request toasts on top

As they're interactive and time-sensitive.

Fixes https://github.com/vector-im/riot-web/issues/12141
---
 src/components/structures/MatrixChat.js |  1 +
 src/stores/ToastStore.js                | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js
index b2f4493d5b..52002f0591 100644
--- a/src/components/structures/MatrixChat.js
+++ b/src/components/structures/MatrixChat.js
@@ -1524,6 +1524,7 @@ export default createReactClass({
                     icon: "verification",
                     props: {request},
                     component: sdk.getComponent("toasts.VerificationRequestToast"),
+                    priority: ToastStore.PRIORITY_REALTIME,
                 });
             }
         });
diff --git a/src/stores/ToastStore.js b/src/stores/ToastStore.js
index 2c4464813b..f17d13bf9e 100644
--- a/src/stores/ToastStore.js
+++ b/src/stores/ToastStore.js
@@ -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) {
-            this._toasts.push(newToast);
+            // 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;
         }