[polari/wip/raresv/nick-popover: 17/27] chatView: replace old status tracking logic with the new one



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

    chatView: replace old status tracking logic with the new one
    
    First, the chatView needs to use the new UserStatusMonitor in order
    to access the UserTracker class, so the old user tracking logic
    needs to be replaced with the new one. The chatView only tracks
    global status changes, hence the null parameter passed to the
    UserTracker.watchRoomStatus() method. The handler used in the
    case of global status changes is the _onStatusChanged() method.

 src/chatView.js |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 08f823a..32add3f 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -297,8 +297,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() {
@@ -351,6 +351,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() {
@@ -1165,6 +1174,7 @@ const ChatView = new Lang.Class({
                     this._view.get_buffer().get_tag_table().add(nickTag);
                 }
                 tags.push(nickTag);
+
                 if (needsGap)
                     tags.push(this._lookupTag('gap'));
                 this._insertWithTags(iter, message.nick + '\t', tags);
@@ -1199,8 +1209,9 @@ const ChatView = new Lang.Class({
         this._insertWithTags(iter, text.substr(pos), tags);
     },
 
-    _onNickStatusChanged: function(tracker, nickName, status) {
-        let nickTag = this._lookupTag(this._getNickTagName(nickName));
+    _onNickStatusChanged: function(baseNick, status) {
+        let nickTagName = this._getNickTagName(baseNick);
+        let nickTag = this._lookupTag(nickTagName);
 
         if (!nickTag)
             return;


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