[polari/wip/fmuellner/window-experiments: 17/24] roomList: Handle accounts immediately when already prepared



commit dfe02bcaaefb3fc0805b362a90dabadeb33ed669
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 14 16:44:41 2016 +0200

    roomList: Handle accounts immediately when already prepared
    
    When the AccountsMonitor's accountManager is already prepared when
    initializing the room list, the ::account-manager-prepared signal
    won't be emitted again and we don't set up change notifications or
    pick up the list of active accounts. Check for this case and call
    the ::account-manager-prepared handler immediately to get proper
    initialization in either case.

 src/roomList.js |   37 ++++++++++++++++++++++---------------
 1 files changed, 22 insertions(+), 15 deletions(-)
---
diff --git a/src/roomList.js b/src/roomList.js
index d621904..51172d5 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -339,21 +339,15 @@ const RoomList = new Lang.Class({
         this._roomRows = {};
 
         this._accountsMonitor = AccountsMonitor.getDefault();
-        this._accountsMonitor.connect('account-manager-prepared', Lang.bind(this,
-            function(mon, am) {
-                let accounts = this._accountsMonitor.dupAccounts();
-                for (let i = 0; i < accounts.length; i++)
-                    this._accountAdded(mon, accounts[i]);
-
-                am.connect('account-enabled', Lang.bind(this,
-                    function(am, account) {
-                        this._updatePlaceholderVisibility(account);
-                    }));
-                am.connect('account-disabled', Lang.bind(this,
-                    function(am, account) {
-                        this._updatePlaceholderVisibility(account);
-                    }));
-            }));
+        let feature = Tp.AccountManager.get_feature_quark_core();
+        let mon = this._accountsMonitor;
+
+        if (mon.accountManager.is_prepared(feature))
+            this._onAccountManagerPrepared(mon, mon.accountManager);
+        else
+            mon.connect('account-manager-prepared',
+                        Lang.bind(this, this._onAccountManagerPrepared));
+
         this._accountsMonitor.connect('account-added',
                                       Lang.bind(this, this._accountAdded));
         this._accountsMonitor.connect('account-removed',
@@ -369,6 +363,19 @@ const RoomList = new Lang.Class({
         action.connect('activate', Lang.bind(this, this._onLeaveActivated));
     },
 
+    _onAccountManagerPrepared: function(mon, am) {
+        let accounts = this._accountsMonitor.dupAccounts();
+        for (let i = 0; i < accounts.length; i++)
+            this._accountAdded(mon, accounts[i]);
+
+        am.connect('account-enabled', (am, account) => {
+                this._updatePlaceholderVisibility(account);
+            });
+        am.connect('account-disabled', (am, account) => {
+                this._updatePlaceholderVisibility(account);
+            });
+    },
+
     vfunc_realize: function() {
         this.parent();
 


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