[polari/wip/raresv/popoverRebasedOnTracker] fix watch() method and add checks for the signal id before calling unwatch()



commit 3fefa476c4e851d4241a051d395a9395aaf4d5e8
Author: raresv <rares visalom gmail com>
Date:   Wed Jul 20 19:26:27 2016 +0300

    fix watch() method and add checks for the signal id before calling unwatch()

 src/chatView.js    |    5 ++++-
 src/userList.js    |    2 +-
 src/userTracker.js |    6 ++----
 3 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 3036748..2d8b435 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -359,7 +359,10 @@ const ChatView = new Lang.Class({
                                         Lang.bind(this, this._onNickStatusChanged));
 
         this.connect('destroy', () => {
-            this._userTracker.unwatchRoomStatus(this._room, this._nickStatusChangedId);
+            if (this._nickStatusChangedId > 0)
+                this._userTracker.unwatchRoomStatus(this._room, this._nickStatusChangedId);
+            this._nickStatusChangedId = 0;
+
             this._userTracker = null;
         });
     },
diff --git a/src/userList.js b/src/userList.js
index dd60742..935e1e9 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -398,7 +398,7 @@ const UserPopover = new Lang.Class({
         /* Nits:
          *  - Convention is to use 'id', not 'signal'
          *  - maybe this._roomStatusChangedId is clearer? */
-        if (this._localStatusChangedSignal)
+        if (this._localStatusChangedSignal > 0)
             this._userTracker.unwatchRoomStatus(this._room, this._localStatusChangedSignal);
         /* this desparately needs line breaks, sth like
         this._localStatusChangedId =
diff --git a/src/userTracker.js b/src/userTracker.js
index 5ac483d..4ad5f9c 100644
--- a/src/userTracker.js
+++ b/src/userTracker.js
@@ -297,20 +297,18 @@ const UserTracker = new Lang.Class({
     watchRoomStatus: function(room, nick, callback) {
         this._ensureRoomMappingForRoom(room);
 
-        this._roomMapping.get(room)._handlerMapping.set(this._handlerCounter, {
+        this._roomMapping.get(room)._handlerMapping.set(++this._handlerCounter, {
             nickName: nick ? Polari.util_get_basenick(nick) : undefined,
             handler: callback
         });
 
-        this._handlerCounter++;
-
         /* it would be good to follow gsignal semantics and not use 0 as
          * a valid handler ID - see the pattern of
                if (this._someSignalId > 0)
                    this._someObject.disconnect(this._someSignalId);
                this._someSignalId = 0;
          * used all over the place */
-        return this._handlerCounter - 1;
+        return this._handlerCounter;
     },
 
     unwatchRoomStatus: function(room, handlerID) {


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