[polari/wip/fmuellner/combined-gsoc: 70/137] Notifications are now based on basenicks and usertracker emits a new detailed signal, notification-e



commit 16eee6d33be7e4ba46e3a3e94e37ee980519e5a5
Author: raresv <rares visalom gmail com>
Date:   Wed Jul 13 00:45:49 2016 +0300

    Notifications are now based on basenicks and usertracker emits a new detailed signal, 
notification-emitted, so that the popover can properly unset the toggled button

 src/userList.js    |   15 +++++++++------
 src/userTracker.js |   22 +++++++++++++++++++---
 2 files changed, 28 insertions(+), 9 deletions(-)
---
diff --git a/src/userList.js b/src/userList.js
index ea8eb39..90193cf 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -381,6 +381,7 @@ const UserPopover = new Lang.Class({
         /*TODO: these need to be disconnected when not used anymore*/
         this._userTracker.watchUser(this._room, this._nickname, Lang.bind(this, this._onNickStatusChanged));
         this._userTracker.connect("status-changed::"+this._nickname, Lang.bind(this, this._updateContents));
+        this._userTracker.connect("notification-emitted::" + baseNick, Lang.bind(this, 
this._onNotificationEmitted))
 
         this._updateContents();
 
@@ -452,35 +453,37 @@ const UserPopover = new Lang.Class({
         if (!this._userTracker.isUserWatched(this._nickname, this._room.account.get_display_name()))
             if (this._userTracker.getNickRoomStatus(this._nickname, this._room) == 
Tp.ConnectionPresenceType.AVAILABLE) {
                 this._notifyButton.visible = false;
-                this._notifyButton.set_active(false);
+                //this._notifyButton.set_active(false);
             }
             else {
-                //this._notifyButton.visible = true;
                 if (isUserGloballyOnline)
                     this._notifyButton.visible = false;
                 else
                     this._notifyButton.visible = true;
 
-                this._notifyButton.set_active(false);
+                //this._notifyButton.set_active(false);
             }
         else
             if (this._userTracker.getNickRoomStatus(this._nickname, this._room) == 
Tp.ConnectionPresenceType.AVAILABLE) {
                 this._notifyButton.visible = false;
-                this._notifyButton.set_active(true);
+                //this._notifyButton.set_active(true);
             }
             else {
-                //this._notifyButton.visibile = true;
                 if (isUserGloballyOnline)
                     this._notifyButton.visible = false;
                 else
                     this._notifyButton.visibile = true;
 
-                this._notifyButton.set_active(true);
+                //this._notifyButton.set_active(true);
             }
     },
 
     _onNickStatusChanged: function(nickName, status) {
         this._updateContents();
+    },
+
+    _onNotificationEmitted: function() {
+        this._notifyButton.set_active(false);
     }
 });
 
diff --git a/src/userTracker.js b/src/userTracker.js
index e5dc0a1..90b660b 100644
--- a/src/userTracker.js
+++ b/src/userTracker.js
@@ -70,6 +70,9 @@ const UserTracker = new Lang.Class({
         },
         'contacts-changed': {
             flags: GObject.SignalFlags.DETAILED
+        },
+        'notification-emitted': {
+            flags: GObject.SignalFlags.DETAILED,
         }
     },
 
@@ -377,12 +380,20 @@ const UserTracker = new Lang.Class({
     },
 
     addToWatchlist: function(user, network) {
-        this._watchlist.push([user, network]);
+        let baseNick = Polari.util_get_basenick(user);
+
+        let isAlreadyWatched = this._watchlist.indexOf([baseNick, network]) != -1;
+
+        if (!isAlreadyWatched)
+            this._watchlist.push([baseNick, network]);
+        //this._watchlist.push([user, network]);
     },
 
     isUserWatched: function (user, network) {
+        let baseNick = Polari.util_get_basenick(user);
+
         for (var i = 0; i < this._watchlist.length; i++) {
-            if (this._watchlist[i][0] == user && this._watchlist[i][1] == network) {
+            if (this._watchlist[i][0] == baseNick && this._watchlist[i][1] == network) {
                 return true;
             }
         }
@@ -391,9 +402,11 @@ const UserTracker = new Lang.Class({
     },
 
     popUserFromWatchlist: function (user, network) {
+        let baseNick = Polari.util_get_basenick(user);
+
         let indexToDelete = -1;
         for (var i = 0; i < this._watchlist.length; i++) {
-            if (this._watchlist[i][0] == user && this._watchlist[i][1] == network) {
+            if (this._watchlist[i][0] == baseNick && this._watchlist[i][1] == network) {
                 indexToDelete = i;
             }
         }
@@ -416,5 +429,8 @@ const UserTracker = new Lang.Class({
         this._app.send_notification('watched-user-notification', notification);
 
         this.popUserFromWatchlist(member.alias, member.get_account().get_display_name());
+
+        let baseNick = Polari.util_get_basenick(member.alias);
+        this.emit("notification-emitted::" + baseNick);
     }
 });


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