[polari/wip/raresv/GSoC: 2/11] userDetails: add offline support



commit 16a63036b0ce38f1e4c780a6e94783e6ffa767d1
Author: raresv <rares visalom gmail com>
Date:   Sun Aug 21 14:49:12 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 be visible just 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.
    We also need to update the messageButton visibility. The _user
    param is not passed at construction time, but is initialized
    through a setter.

 src/userList.js |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)
---
diff --git a/src/userList.js b/src/userList.js
index 4daafa1..07fa08c 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -131,6 +131,27 @@ 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;
 
@@ -169,6 +190,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() {
@@ -233,6 +257,10 @@ const UserDetails = new Lang.Class({
             this._lastLabel.hide();
         }
 
+        this._revealDetails();
+    },
+
+    _revealDetails: function() {
         this._spinner.stop();
         this._spinnerBox.hide();
         this._detailsGrid.show();
@@ -252,7 +280,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 {
@@ -325,7 +359,9 @@ const UserListRow = new Lang.Class({
         if (this._revealer.get_child())
             return;
 
-        let details = new UserListDetails({ user: this._user })
+        let details = new UserDetails();
+        details.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]