[polari/wip/raresv/finalRebase: 15/18] chatView: split _onStatusChangedCallback() method. Replace the use of the old global tracker with th



commit 865b5819dd8a5b2cd83d70b5cf7d3ceb98f9f59a
Author: raresv <rares visalom gmail com>
Date:   Thu Aug 18 20:45:22 2016 +0300

    chatView: split _onStatusChangedCallback() method. Replace the use of the old global tracker with the new 
one.

 src/chatView.js |   36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 12d9c3b..a56df99 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -298,8 +298,8 @@ const ChatView = new Lang.Class({
         this._pendingLogs = [];
         this._statusCount = { left: 0, joined: 0, total: 0 };
 
-        this._userTracker = new UserTracker.UserTracker(this._room);
-        this._userTracker.connect('status-changed', Lang.bind(this, this._onNickStatusChanged));
+        let statusMonitor = UserTracker.getUserStatusMonitor();
+        this._userTracker = statusMonitor.getUserTrackerForAccount(room.account);
 
         this._room.account.connect('notify::nickname', Lang.bind(this,
             function() {
@@ -352,6 +352,15 @@ const ChatView = new Lang.Class({
             this._roomSignals.push(room.connect(signal.name, signal.handler));
         }));
         this._onChannelChanged();
+
+        this._nickStatusChangedId =
+            this._userTracker.watchRoomStatus(this._room, null,
+                                        Lang.bind(this, this._onNickStatusChanged));
+
+        this.connect('destroy', () => {
+            this._userTracker.unwatchRoomStatus(this._room, this._nickStatusChangedId);
+            this._userTracker = null;
+        });
     },
 
     _createTags: function() {
@@ -766,15 +775,6 @@ const ChatView = new Lang.Class({
         return NICKTAG_PREFIX + Polari.util_get_basenick(nick);
     },
 
-    _onNickStatusChanged: function(tracker, nickName, status) {
-        let nickTag = this._lookupTag(this._getNickTagName(nickName));
-
-        if (!nickTag)
-            return;
-
-        this._updateNickTag(nickTag, status);
-    },
-
     _onChannelChanged: function() {
         if (this._channel == this._room.channel)
             return;
@@ -1175,9 +1175,11 @@ const ChatView = new Lang.Class({
                     nickTag = this._createNickTag(nickTagName);
                     buffer.get_tag_table().add(nickTag);
 
-                    this._updateNickTag(nickTag, this._userTracker.getNickStatus(message.nick));
+                    let status = this._userTracker.getNickStatus(message.nick);
+                    this._updateNickTag(nickTag, status);
                 }
                 tags.push(nickTag);
+
                 if (needsGap)
                     tags.push(this._lookupTag('gap'));
                 this._insertWithTags(iter, message.nick, tags);
@@ -1213,6 +1215,16 @@ const ChatView = new Lang.Class({
         this._insertWithTags(iter, text.substr(pos), tags);
     },
 
+    _onNickStatusChanged: function(baseNick, status) {
+        let nickTagName = this._getNickTagName(baseNick);
+        let nickTag = this._lookupTag(nickTagName);
+
+        if (!nickTag)
+            return;
+
+        this._updateNickTag(nickTag, status);
+    },
+
     _updateNickTag: function(tag, status) {
         if (status == Tp.ConnectionPresenceType.AVAILABLE)
             tag.foreground_rgba = this._activeNickColor;


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