[polari/wip/bastianilso/error-handling: 7/7] Show notifications on a per room/server basis



commit 1a8f672c0d94d0803f5d314469594b6645c602a6
Author: Bastian Ilsø <bastianilso src gnome org>
Date:   Sat Jul 18 09:18:53 2015 +0200

    Show notifications on a per room/server basis
    
    Error messages adds an extra amount of notifications to Polari.
    This patch shows notifications based on what room on what
    server is active. Pending notifications from inactive rooms
    or servers are indicated with a symbol in the room list.

 src/appNotifications.js |   67 ++++++++++++++++++++++++++++++++++++++++------
 src/mainWindow.js       |   36 ++++++++++++++----------
 2 files changed, 79 insertions(+), 24 deletions(-)
---
diff --git a/src/appNotifications.js b/src/appNotifications.js
index 73435f4..44b37c2 100644
--- a/src/appNotifications.js
+++ b/src/appNotifications.js
@@ -225,20 +225,69 @@ const NotificationQueue = new Lang.Class({
         this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL,
                                     row_spacing: 6, visible: true });
         this.widget.add(this._grid);
+        this._notifications = {};
+        this._activeNotifications = {};
     },
 
-    addNotification: function(notification) {
-        this._grid.add(notification.widget);
+    setNotification: function(identifier, notification) {
+        this._notifications[identifier] = notification;
+        log('checking if ' + identifier + ' is active..');
+        if (this._activeNotifications[identifier])
+                this._displayNotification(identifier, notification);
+        }));
+    },
 
-        notification.widget.connect('destroy',
-                                    Lang.bind(this, this._onChildDestroy));
-        this.widget.show();
+    loadNotifications: function(identifier) {
+        log('checking if ' + this._identifiers + ' is equal to ' + identifier);
+        if (this._activeNotifications[identifier])
+            return;
+
+        let gridChildren = this._grid.get_children();
+        if (gridChildren) {
+            gridChildren.forEach(Lang.bind(this, function(child) {
+                log('checking between ' + child + ' and ' + );
+                if (this._notifications[identifier] == notification) {
+                    log(notification + ' removed');
+                    this._grid.remove(notification);
+                }
+            }));
+        }
+        log('checking if there are notifications for ' + identifier);
+        if (!this._notifications[identifier]) {
+            if (this._grid.get_children().length == 0)
+                this.widget.hide();
+            return;
+        }
+
+        log('displaying notifications for ' + identifier);
+
+        let notification = this._notifications[identifier];
+        this._displayNotification(notification);
+        this._identifiers.push(identifier);
     },
 
-    _onChildDestroy: function() {
-        if (this._grid.get_children().length == 0)
-           this.widget.hide();
-    }
+    _displayNotification: function(identifier, notification) {
+        log('displaying notification: ' + notification);
+
+        if (this._activeNotifications[identifier]) {
+            this._grid.get_children.forEach(Lang.bind(this, function(notification) {
+                    log('checking if ' + this._activeNotifications[identifier] +' vs ' + notification)
+                    if (this._activeNotifications[identifier] == notification)
+                        notification.destroy();
+            }));
+
+        }
+
+        if (!notification) {
+            if (this._grid.get_children().length == 0)
+                this.widget.hide();
+            return;
+        }
+
+        this._grid.add(notification.widget);
+        this._activeNotifications[identifier] = notification.widget;
+        this.widget.show();
+    },
 });
 
 const CommandOutputQueue = new Lang.Class({
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 263247d..593f391 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -120,42 +120,42 @@ const MainWindow = new Lang.Class({
     },
 
     _onAccountChanged: function(am, account) {
-        log(account.display_name + ': ***********');
-        log(account.display_name + ': new change!');
-        let notification, statusReason = null;
+        log('***********');
+        if (!account.connection_status_reason)
+            return;
+        let notification = null;
+        let app = Gio.Application.get_default();
+        let statusReason = account.connection_status_reason;
         if (account.connection_status == Tp.ConnectionStatus.CONNECTING) {
             log(account.display_name + ': we are connecting to the server..');
             notification = new AppNotifications.ConnectingNotification(account);
         } else if (account.connection_status == Tp.ConnectionStatus.DISCONNECTED) {
-            if (!account.connection_status_reason)
-                return;
-            statusReason = account.connection_status_reason;
             if (statusReason == Tp.ConnectionStatusReason.REQUESTED)
                 return;
-
             notification = new AppNotifications.ErrorNotification(account,
                                                                   this.window,
                                                                   statusReason);
             log(account.display_name + ': we are disconnected due to error: ' + 
account.connection_status_reason);
         }
-        if (!notification)
-            return;
 
         let oldReason = account.notification ? account.notification.statusReason
                                              : null;
-        if (oldReason == notification.statusReason) {
-            log(account.display_name + ': same notification is already visible');
+        log(account.display_name + ': comparing ' + oldReason + ' with ' + statusReason);
+        if (notification && oldReason == statusReason) {
+            log(account.display_name + ': same notification is already in queue');
             log(account.display_name + ': ignoring ' + notification)
             return;
         }
-        log(account.notification + ' is not equal to ' + notification);
-        log(account.display_name + ': displaying ' + notification)
-        let app = Gio.Application.get_default();
+        // add a notification for the account to the queue.
 
-        app.notificationQueue.addNotification(notification);
+        let identifier = account.get_path_suffix();
+        app.notificationQueue.setNotification(identifier, notification);
+        log(account.display_name + ': notification set to ' + notification + ' for ' + identifier);
         app.mark_busy();
 
         account.notification = notification;
+        if (!notification)
+            return;
         notification.widget.connect('destroy',
             function() {
                 app.unmark_busy();
@@ -206,6 +206,12 @@ const MainWindow = new Lang.Class({
         this._membersChangedId =
             this._room.connect('members-changed',
                                Lang.bind(this, this._updateUserListLabel));
+        let app = Gio.Application.get_default();
+        app.notificationQueue.loadNotifications(room.account.get_path_suffix());
+        app.notificationQueue.loadNotifications(room.id);
+       // did we change server? if so, load the server's notifications
+       // does the room we are at have a notification? if so, show it too
+       // display the notifications
     },
 
     _createWidget: function(app) {


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