[polari] userList: Fix user count



commit 902796fabf98749a3156ad9d8a797894c23c929a
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Oct 28 20:27:24 2013 +0100

    userList: Fix user count
    
    We currently set/update the user count according to the number of
    rows in the list. As we shortcut setting/updating the header in
    case it's unneeded, we can end up with a count that is less than
    the actual number of users.
    To fix, base the counter on the number of users rather than widgets,
    and make sure to always update it on room member changes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710655

 src/userList.js |   23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)
---
diff --git a/src/userList.js b/src/userList.js
index c4cedd1..a002fef 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -340,6 +340,8 @@ const UserList = new Lang.Class({
                      Lang.bind(this, this._onMemberRemoved));
         room.connect('member-joined',
                      Lang.bind(this, this._onMemberJoined));
+        room.connect('members-changed',
+                     Lang.bind(this, this._onMembersChanged));
 
         let members = room.channel.group_dup_members_contacts();
         for (let i = 0; i < members.length; i++)
@@ -366,6 +368,11 @@ const UserList = new Lang.Class({
         this._addMember(member);
     },
 
+    _onMembersChanged: function(room) {
+        let numMembers = room.channel.group_dup_members_contacts().length;
+        this._counterLabel.label = numMembers.toString();
+    },
+
     _addMember: function(member) {
         let row = new UserListRow(member);
         this._rows[member] = row;
@@ -401,18 +408,16 @@ const UserList = new Lang.Class({
     },
 
     _updateHeader: function(row, before) {
-        let numMembers = this._list.get_children().length;
-
         if (before) {
             row.set_header(null);
             return;
         }
 
-        let header = this._list.get_row_at_index(0).get_header();
-        if (header) {
-            header._counterLabel.label = numMembers.toString();
+        if (row.get_header())
             return;
-        }
+
+        let members = this._room.channel.group_dup_members_contacts();
+        let numMembers = members.length;
 
         let box = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
                                 margin_left: 6,
@@ -422,9 +427,9 @@ const UserList = new Lang.Class({
                                 use_markup: true,
                                 hexpand: true,
                                 halign: Gtk.Align.START }));
-        box._counterLabel = new Gtk.Label({ label: numMembers.toString(),
-                                            halign: Gtk.Align.END });
-        box.add(box._counterLabel);
+        this._counterLabel = new Gtk.Label({ label: numMembers.toString(),
+                                             halign: Gtk.Align.END });
+        box.add(this._counterLabel);
         box.show_all();
 
         row.set_header(box);


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