[polari/wip/fmuellner/combined-gsoc: 69/137] the notify label is now shown when needed, the message button is updated based on the global status,



commit d0701a7e479761ff85e1b4fe4aa75f4288fe0cde
Author: raresv <rares visalom gmail com>
Date:   Tue Jul 12 19:00:16 2016 +0300

    the notify label is now shown when needed, the message button is updated based on the global status, and 
usertracker now emits a contacts-changed::basenick detailed signal to update the user in the UserDetails class

 src/chatView.js    |    2 +-
 src/userList.js    |   43 +++++++++++++++++++++++++++++++++----------
 src/userTracker.js |   28 +++++++++++++++++-----------
 3 files changed, 51 insertions(+), 22 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index 8ddb56a..086c17f 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -1283,7 +1283,7 @@ const ChatView = new Lang.Class({
 
     _createNickTag: function(name) {
         let tag = new ButtonTag({ name: name });
-        tag._popover = new UserList.UserPopover({ relative_to: this._view, margin: 0, room: this._room, 
userTracker: this._userStatusMonitor.getUserTrackerForAccount(this._room.account) });
+        tag._popover = new UserList.UserPopover({ relative_to: this._view, margin: 0, room: this._room, 
userTracker: this._userStatusMonitor.getUserTrackerForAccount(this._room.account), width_request: 280 });
         tag.connect('clicked', Lang.bind(this, this._onNickTagClicked));
         return tag;
     },
diff --git a/src/userList.js b/src/userList.js
index b269d9d..ea8eb39 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -120,7 +120,12 @@ const UserDetails = new Lang.Class({
                                                         'expanded',
                                                         'expanded',
                                                         READWRITE,
-                                                        false)},
+                                                        false),
+                  'isUserWatched': GObject.ParamSpec.boolean('isUserWatched',
+                                                             'isUserWatched',
+                                                             'isUserWatched',
+                                                             READWRITE,
+                                                             false)},
 
     _init: function(params) {
         this._expanded = false;
@@ -132,6 +137,13 @@ const UserDetails = new Lang.Class({
 
         this._updateButtonVisibility();
         this._detailsGrid.hide();
+
+        this._notificationLabel.set_text("Will notify if user appears online.");
+
+        this.bind_property('isUserWatched', this._notificationIcon, 'visible', 
GObject.BindingFlags.SYNC_CREATE);
+        this.bind_property('isUserWatched', this._notificationLabel, 'visible', 
GObject.BindingFlags.SYNC_CREATE);
+
+        this._fullnameLabel.ellipsize = Pango.EllipsizeMode.END;
     },
 
     set user(user) {
@@ -267,8 +279,8 @@ const UserDetails = new Lang.Class({
             this._lastLabel.hide();
         }
 
-        this._notificationIcon.hide();
-        this._notificationLabel.hide();
+        //this._notificationIcon.hide();
+        //this._notificationLabel.hide();
 
         this._revealDetails();
     },
@@ -357,6 +369,8 @@ const UserPopover = new Lang.Class({
         this.add(this._vbox);
 
         this._vbox.show_all();
+
+        this._notifyButton.bind_property('active', this._userDetails, 'isUserWatched', 
GObject.BindingFlags.SYNC_CREATE);
     },
 
     set nickname(nickname) {
@@ -369,6 +383,15 @@ const UserPopover = new Lang.Class({
         this._userTracker.connect("status-changed::"+this._nickname, Lang.bind(this, this._updateContents));
 
         this._updateContents();
+
+        /*TODO: disconnect when not needed anymore*/
+
+        if (this._contactsChangedSignal)
+            this._userTracker.disconnect(this._contactsChangedSignal);
+
+        this._contactsChangedSignal = this._userTracker.connect("contacts-changed::" + baseNick, () => {
+            this._userDetails.user = this._userTracker.lookupContact(this._nickname);
+        });
     },
 
     get nickname() {
@@ -376,16 +399,16 @@ const UserPopover = new Lang.Class({
     },
 
     _updateContents: function() {
-        let bestMatchingContact = this._userTracker.getBestMatchingContactInRoom(this._room, this._nickname);
+        let bestMatchingContact = this._userTracker.lookupContact(this._nickname);
 
         this._nickLabel.set_label(this._nickname);
 
         let labelStatus = "";
-        if (bestMatchingContact)
-            labelStatus = "<small>Online</small>";
+        if (!bestMatchingContact)
+            labelStatus = "<small>Offline</small>";
         else
-            if (this._userTracker.getNickStatus(this._nickname) == Tp.ConnectionPresenceType.OFFLINE)
-                labelStatus = "<small>Offline</small>";
+            if (this._userTracker.getNickRoomStatus(this._nickname, this._room) == 
Tp.ConnectionPresenceType.AVAILABLE)
+                labelStatus = "<small>Online</small>";
             else
                 labelStatus = "<small>Available in another room.</small>";
 
@@ -427,7 +450,7 @@ const UserPopover = new Lang.Class({
 
         /*TODO: too many conditionals*/
         if (!this._userTracker.isUserWatched(this._nickname, this._room.account.get_display_name()))
-            if (this._userTracker.getBestMatchingContactInRoom(this._room, this._nickname)) {
+            if (this._userTracker.getNickRoomStatus(this._nickname, this._room) == 
Tp.ConnectionPresenceType.AVAILABLE) {
                 this._notifyButton.visible = false;
                 this._notifyButton.set_active(false);
             }
@@ -441,7 +464,7 @@ const UserPopover = new Lang.Class({
                 this._notifyButton.set_active(false);
             }
         else
-            if (this._userTracker.getBestMatchingContactInRoom(this._room, this._nickname)) {
+            if (this._userTracker.getNickRoomStatus(this._nickname, this._room) == 
Tp.ConnectionPresenceType.AVAILABLE) {
                 this._notifyButton.visible = false;
                 this._notifyButton.set_active(true);
             }
diff --git a/src/userTracker.js b/src/userTracker.js
index e5fca68..e5dc0a1 100644
--- a/src/userTracker.js
+++ b/src/userTracker.js
@@ -68,6 +68,9 @@ const UserTracker = new Lang.Class({
             flags: GObject.SignalFlags.DETAILED,
             param_types: [GObject.TYPE_STRING, GObject.TYPE_INT]
         },
+        'contacts-changed': {
+            flags: GObject.SignalFlags.DETAILED
+        }
     },
 
     _init: function(account) {
@@ -267,7 +270,7 @@ const UserTracker = new Lang.Class({
         else
             map.set(baseNick, [member]);
 
-        if (map.get(baseNick).length == 1)
+        if (map.get(baseNick).length == 1) {
             if (map == this._globalContactMapping) {
                 this.emit("status-changed::" + baseNick, member.alias, Tp.ConnectionPresenceType.AVAILABLE);
                 //log("[global status] user " + member.alias + " is globally online");
@@ -279,30 +282,34 @@ const UserTracker = new Lang.Class({
                         handlerInfo.handler(handlerInfo.nickName, Tp.ConnectionPresenceType.AVAILABLE);
                     else if (!handlerInfo.nickName)
                         handlerInfo.handler(member.alias, Tp.ConnectionPresenceType.AVAILABLE);
+
+            if (this._globalContactMapping == map)
+                this.emit("contacts-changed::" + baseNick);
+        }
     },
 
     _untrackMember: function(map, member, room) {
         let baseNick = Polari.util_get_basenick(member.alias);
 
         let contacts = map.get(baseNick) || [];
-        /*i really don't like this search. maybe use a for loop?*/
+        /*TODO: i really don't like this search. maybe use a for loop?*/
         let indexToDelete = contacts.map(c => c.alias + "|" + c._room.channelName).indexOf(member.alias + 
"|" + member._room.channelName);
 
         if (indexToDelete > -1) {
             let removedMember = contacts.splice(indexToDelete, 1)[0];
 
             if (contacts.length == 0)
-                if (map == this._globalContactMapping) {
+                if (map == this._globalContactMapping)
                     this.emit("status-changed::" + baseNick, member.alias, 
Tp.ConnectionPresenceType.OFFLINE);
-                    //log("[global status] user " + member.alias + " is globally offline");
-                }
                 else
-                    //log("[Local UserTracker] User " + member.alias + " is now offline in room " + 
member._room.channelName + " on " + this._account.get_display_name());
                     for ([handlerID, handlerInfo] of this._roomMapping.get(room)._handlerMapping)
                         if (handlerInfo.nickName == member.alias)
                             handlerInfo.handler(handlerInfo.nickName, Tp.ConnectionPresenceType.OFFLINE);
                         else if (!handlerInfo.nickName)
                             handlerInfo.handler(member.alias, Tp.ConnectionPresenceType.OFFLINE);
+
+            if (this._globalContactMapping == map)
+                this.emit("contacts-changed::" + baseNick);
         }
     },
 
@@ -314,14 +321,11 @@ const UserTracker = new Lang.Class({
                                     : Tp.ConnectionPresenceType.AVAILABLE;
     },
 
-    getBestMatchingContactInRoom: function(room, nickName) {
+    lookupContact: function(nickName) {
         let baseNick = Polari.util_get_basenick(nickName);
 
-        this._ensureContactMappingForRoom(room);
-
-        let contacts = this._roomMapping.get(room)._contactMapping.get(baseNick) || [];
+        let contacts = this._globalContactMapping.get(baseNick) || [];
 
-        /*TODO: even possible?*/
         if (contacts.length == 0)
             return null;
 
@@ -335,6 +339,8 @@ const UserTracker = new Lang.Class({
     getNickRoomStatus: function(nickName, room) {
         let baseNick = Polari.util_get_basenick(nickName);
 
+        this._ensureContactMappingForRoom(room);
+
         let contacts = this._roomMapping.get(room)._contactMapping.get(baseNick) || [];
         return contacts.length == 0 ? Tp.ConnectionPresenceType.OFFLINE
                                     : Tp.ConnectionPresenceType.AVAILABLE;


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