[polari/wip/bastianilso/error-handling: 10/10] application.js: reconnectAccount implementation



commit b91ca2ea89ad0b66648c03b75b0677ab101f42d7
Author: Bastian Ilsø <bastianilso src gnome org>
Date:   Wed Jul 29 21:36:56 2015 +0200

    application.js: reconnectAccount implementation

 src/application.js |   44 ++++++++++++++++++++++++++++++++------------
 1 files changed, 32 insertions(+), 12 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 297fa4b..05e2b1d 100644
--- a/src/application.js
+++ b/src/application.js
@@ -39,6 +39,8 @@ const Application = new Lang.Class({
         let w = new Polari.FixedSizeFrame(); // register gtype
         w.destroy();
 
+        this._rooms = {};
+
         this._chatroomManager = ChatroomManager.getDefault();
         this._accountsMonitor = AccountsMonitor.getDefault();
 
@@ -196,18 +198,18 @@ const Application = new Lang.Class({
     },
 
     _onAccountChanged: function(am, account) {
-        // We reset the notification when account changes because
-        // External parties can make the account reconnect while
-        // we are showing an error.
-        // Fx. the case where we are try to connect, then disconnect, then reconnect.
-        // We get a network error and then somehow we begin reconnecting again.
-        log('account changed to ' + account.connection_error + ', resetting notification.');
+        if (account.connection_status != Tp.ConnectionStatus.CONNECTED)
+            return;
+
+        // Some thirdparty might be trying to reconnect the account
+        // We can safely assume that there are no account errors when
+        // we successfully connected the account to the server.
+
         let accountError = { notification: null,
                              type: 'account',
                              identifier: account.get_path_suffix() };
         this.notificationQueue.setNotification(accountError);
 
-
     },
 
     _addSavedChannel: function(account, channel) {
@@ -260,6 +262,21 @@ const Application = new Lang.Class({
         account.update_parameters_vardict_async(asv, [], callback);
     },
 
+    _reconnectAccount: function(accountPath) {
+        // Request online presence inside accountsMonitor, when it becomes
+        // enabled and when we initialize accounts.
+
+        let accountError = { notification: null,
+                             type: 'account',
+                             identifier: account.get_path_suffix() };
+        this.notificationQueue.setNotification(accountError);
+
+        let keys = Object.keys(this._rooms[accountPath]);
+        keys.forEach(Lang.bind(this, function(roomId) {
+            this._ensureChannel(this._rooms[accountPath][roomId]);
+            }));
+    },
+
     _requestChannel: function(accountPath, targetType, targetId, time) {
         // have this in AccountMonitor?
         let factory = Tp.AccountManager.dup().get_factory();
@@ -274,7 +291,7 @@ const Application = new Lang.Class({
             return;
         }
 
-        let roomId = Polari.create_room_id(account,  targetId, targetType);
+        let roomId = Polari.create_room_id(account, targetId, targetType);
 
         let requestData = {
           account: account,
@@ -286,7 +303,9 @@ const Application = new Lang.Class({
           retry: 0,
           originalNick: account.nickname };
 
-        this._pendingRequests[roomId] = requestData;
+        if (!this._rooms[accountPath])
+            this._rooms[accountPath] = {};
+        this._rooms[accountPath][roomId] = requestData;
 
         this._ensureChannel(requestData);
     },
@@ -323,7 +342,7 @@ const Application = new Lang.Class({
             if (requestData.targetHandleType == Tp.HandleType.ROOM)
                 this._addSavedChannel(account, requestData.targetId);
         } catch (e if e.matches(Tp.Error, Tp.Error.DISCONNECTED)) {
-            //let error = account.connection_error;
+            let error = account.connection_error;
             // If we receive an error and the network is unavailable,
             // then the error is not specific to polari and polari will
             // just be in offline state.
@@ -384,9 +403,10 @@ const Application = new Lang.Class({
         let factory = Tp.AccountManager.dup().get_factory();
         let accountPath = parameter.unpack();
         log(accountPath);
-        let account = factory.ensure_account(accountPath, []);
+        this._reconnectAccount(accountPath);
+        /*let account = factory.ensure_account(accountPath, []);
         this._chatroomManager.restoreSavedChannels(account);
-        /*account.reconnect_async(Lang.bind(this, function(a, res) {
+        account.reconnect_async(Lang.bind(this, function(a, res) {
                 account.reconnect_finish(res);
             }));*/
     },


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