[gnome-shell/wip/fmuellner/notification-redux+sass: 123/141] messageTray: Limit number of notifications per source



commit d53c7e733d9c123ae669e37a6c1fe34dd8571233
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Feb 14 00:06:11 2015 +0100

    messageTray: Limit number of notifications per source
    
    While applications can no longer spam the users with a constant stream
    of banner notifications, it is still possible to drown the summary in
    the message list. Avoid this by limiting the number of notifications a
    single source is allowed to display simultaniously.
    
    test-xy-stress in libnotify's tests suddenly became fun again ...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744850

 js/ui/messageTray.js |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js
index 7dfa6c0..6b19d20 100644
--- a/js/ui/messageTray.js
+++ b/js/ui/messageTray.js
@@ -28,6 +28,7 @@ const HIDE_TIMEOUT = 0.2;
 const LONGER_HIDE_TIMEOUT = 0.6;
 
 const MAX_NOTIFICATIONS_IN_QUEUE = 3;
+const MAX_NOTIFICATIONS_PER_SOURCE = 3;
 
 // We delay hiding of the tray if the mouse is within MOUSE_LEFT_ACTOR_THRESHOLD
 // range from the point where it left the tray.
@@ -43,10 +44,10 @@ const State = {
 };
 
 // These reasons are useful when we destroy the notifications received through
-// the notification daemon. We use EXPIRED for transient notifications that the
-// user did not interact with, DISMISSED for all other notifications that were
-// destroyed as a result of a user action, and SOURCE_CLOSED for the notifications
-// that were requested to be destroyed by the associated source.
+// the notification daemon. We use EXPIRED for notifications that we dismiss
+// and the user did not interact with, DISMISSED for all other notifications
+// that were destroyed as a result of a user action, and SOURCE_CLOSED for the
+// notifications that were requested to be destroyed by the associated source.
 const NotificationDestroyedReason = {
     EXPIRED: 1,
     DISMISSED: 2,
@@ -1304,6 +1305,9 @@ const Source = new Lang.Class({
         if (this.notifications.indexOf(notification) >= 0)
             return;
 
+        while (this.notifications.length >= MAX_NOTIFICATIONS_PER_SOURCE)
+            this.notifications.shift().destroy(NotificationDestroyedReason.EXPIRED);
+
         notification.connect('destroy', Lang.bind(this, this._onNotificationDestroy));
         notification.connect('acknowledged-changed', Lang.bind(this, this.countUpdated));
         this.notifications.push(notification);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]