[polari] chatView: Fix handling of channel changes



commit fce1a61c287c8afb5aff9c023e72356584ba5e5b
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Apr 11 16:50:29 2014 +0200

    chatView: Fix handling of channel changes
    
    The current handling is sketchy at best - when the channel is not
    unset entirely, we disconnect the old channel signal connections,
    but using the already updated channel property. It does work because
    a room's channel will be unset before it actually changes, but it's
    still ugly. Just keep track of the channel separately, which also
    allows to handle the case of the same channel being notified repeatedly
    better than commit d71c13289adcaa14 did.

 src/chatView.js |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index af9405c..b1b058e 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -115,6 +115,7 @@ const ChatView = new Lang.Class({
         this._linkCursor = Gdk.Cursor.new(Gdk.CursorType.HAND1);
 
         this._channelSignals = [];
+        this._channel = null;
 
         let roomSignals = [
             { name: 'notify::channel',
@@ -136,6 +137,7 @@ const ChatView = new Lang.Class({
         roomSignals.forEach(Lang.bind(this, function(signal) {
             this._roomSignals.push(room.connect(signal.name, signal.handler));
         }));
+        this._onChannelChanged();
     },
 
     _createTags: function() {
@@ -466,14 +468,20 @@ const ChatView = new Lang.Class({
     },
 
     _onChannelChanged: function() {
-        if (!this._room.channel) {
-            this._channelSignals = [];
+        if (this._channel == this._room.channel)
             return;
+
+        if (this._channel) {
+            for (let i = 0; i < this._channelSignals.length; i++)
+                this._channel.disconnect(this._channelSignals[i]);
+            this._channelSignals = [];
         }
 
-        for (let i = 0; i < this._channelSignals.length; i++)
-            this._room.channel.disconnect(this._channelSignals[i]);
-        this._channelSignals = [];
+        this._channel = this._room.channel;
+
+        if (!this._channel)
+            return;
+
 
         let channelSignals = [
             { name: 'message-received',
@@ -489,9 +497,6 @@ const ChatView = new Lang.Class({
 
         this._room.channel.dup_pending_messages().forEach(Lang.bind(this,
             function(message) {
-                let [id, ] = message.get_pending_message_id();
-                if (this._pending[id])
-                    return;
                 this._insertTpMessage(this._room, message);
             }));
         this._checkMessages();


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