[polari/wip/raresv/nick-popover: 142/149] userDetails: Add offline support



commit 06d5ad80755987f507e32d6cb62cf579476bffcf
Author: raresv <rares visalom gmail com>
Date:   Sun Sep 4 19:48:50 2016 +0300

    userDetails: Add offline support
    
    We want to be able to use the UserDetails class both when the
    user is offline and online. The offline functionality of the
    UserDetails class will only be visible in the UserPopover,
    as there are no offline users displayed in the UserList. We
    know which case we are in by the presence of the _user variable,
    which is passed as parameter at construction time. We also update
    the messageButton visibility whenever we set the _user variable,
    as messaging a user is only available in the online case, and only
    when the user is different from self.

 src/userList.js |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/src/userList.js b/src/userList.js
index d1deac4..e247672 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -118,8 +118,8 @@ const UserDetails = new Lang.Class({
                                                         READWRITE,
                                                         false)},
 
-    _init: function(params) {
-        this._user = params.user;
+    _init: function(params = {}) {
+        let user = params.user;
         delete params.user;
 
         this._expanded = false;
@@ -127,6 +127,8 @@ const UserDetails = new Lang.Class({
 
         this.parent(params);
 
+        this.user = user;
+
         this._messageButton.connect('clicked',
                                     Lang.bind(this, this._onMessageButtonClicked));
 
@@ -134,6 +136,37 @@ const UserDetails = new Lang.Class({
         this._detailsGrid.hide();
     },
 
+    set user(user) {
+        if (this._user == user)
+            return;
+
+        if (this._user)
+            this._user.connection.disconnect(this._selfContactChangedId);
+        this._selfContactChangedId = 0;
+
+        this._user = user;
+
+        if (this._user)
+            this._selfContactChangedId = this._user.connection.connect('notify::self-contact',
+                                                    Lang.bind(this, this._updateButtonVisibility));
+
+        if (this.expanded)
+            this._expand();
+
+        this._updateButtonVisibility();
+        this._lastLabel.visible = this._user != null;
+    },
+
+    set nickname(nickname) {
+        this._nickname = nickname;
+
+        if (!this._fullnameLabel.label)
+            this._fullnameLabel.label = this._nickname || '';
+
+
+        this._updateButtonVisibility();
+    },
+
     get expanded() {
         return this._expanded;
     },
@@ -162,6 +195,9 @@ const UserDetails = new Lang.Class({
         if (this._user)
             this._user.request_contact_info_async(this._cancellable,
                                               Lang.bind(this, this._onContactInfoReady));
+        //TODO: else use this._nickname to query tracker
+        else
+            this._revealDetails();
     },
 
     _unexpand: function() {
@@ -226,6 +262,10 @@ const UserDetails = new Lang.Class({
             this._lastLabel.hide();
         }
 
+        this._revealDetails();
+    },
+
+    _revealDetails: function() {
         this._spinner.stop();
         this._spinnerBox.hide();
         this._detailsGrid.show();
@@ -245,7 +285,13 @@ const UserDetails = new Lang.Class({
     },
 
     _updateButtonVisibility: function() {
-        if (!this._user || this._user == this._user.connection.self_contact) {
+        if (!this._user) {
+            this._messageButton.sensitive = false;
+
+            return;
+        }
+
+        if (this._user == this._user.connection.self_contact) {
             this._messageButton.visible = false;
             this._messageButton.sensitive = true;
         } else {
@@ -318,6 +364,7 @@ const UserListRow = new Lang.Class({
             return;
 
         let details = new UserDetails({ user: this._user });
+
         this._revealer.bind_property('reveal-child', details, 'expanded', 0);
 
         this._revealer.add(details);


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