[polari/wip/raresv/nick-popover: 9/16] userDetails: Add offline support.



commit 12d7a002642450988c895e339ec1642cb84d01d0
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 |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 51 insertions(+), 4 deletions(-)
---
diff --git a/src/userList.js b/src/userList.js
index bd2dba6..e335698 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -115,9 +115,11 @@ const UserDetails = new Lang.Class({
                                                         READWRITE,
                                                         false)},
 
-    _init: function(params) {
-        this._user = params.user;
-        delete params.user;
+    _init: function(params = {}) {
+        if (params.user) {
+            this._user = params.user;
+            delete params.user;
+        }
 
         this._expanded = false;
         this._initialDetailsLoaded = false;
@@ -131,6 +133,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;
     },
@@ -159,6 +192,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() {
@@ -223,6 +259,10 @@ const UserDetails = new Lang.Class({
             this._lastLabel.hide();
         }
 
+        this._revealDetails();
+    },
+
+    _revealDetails: function() {
         this._spinner.stop();
         this._spinnerBox.hide();
         this._detailsGrid.show();
@@ -242,7 +282,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 {
@@ -315,6 +361,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]