[polari] Restore saved channels when an account is reconnected



commit d4903844ebc032e3a45c1c811b18960125dff85a
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Jul 8 18:01:58 2014 +0200

    Restore saved channels when an account is reconnected
    
    If an account is reconnected after a transient network failure
    (that is not picked up by GNetworkMonitor), rejoin all its channels,
    otherwise we end up connected but outside all rooms.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732905

 src/chatroomManager.js |   19 ++++++++++++++-----
 1 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index f4ef024..f481801 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -86,20 +86,28 @@ const _ChatroomManager = new Lang.Class({
         this._client.register();
 
         am.connect('account-enabled',
-                   Lang.bind(this, this._restoreSavedChannels));
+                   Lang.bind(this, this._onAccountEnabled));
         am.connect('account-disabled',
                    Lang.bind(this, this._onAccountDisabled));
         am.connect('account-removed',
                    Lang.bind(this, this._onAccountDisabled));
-        this._restoreSavedChannels();
+        this._accountsMonitor.connect('account-status-changed', Lang.bind(this, function(monitor, account) {
+            if (account.connection_status == Tp.ConnectionStatus.CONNECTED)
+                this._restoreSavedChannels(account);
+        }));
+        this._restoreSavedChannels(null);
 
         this._networkMonitor.connect('notify::network-available', Lang.bind(this,
             function() {
                 if (this._networkMonitor.network_available)
-                    this._restoreSavedChannels();
+                    this._restoreSavedChannels(null);
             }));
     },
 
+    _onAccountEnabled: function(am, account) {
+        this._restoreSavedChannels(account);
+    },
+
     _onAccountDisabled: function(am, account) {
         for (let id in this._rooms) {
             let room = this._rooms[id];
@@ -108,7 +116,7 @@ const _ChatroomManager = new Lang.Class({
         }
     },
 
-    _restoreSavedChannels: function() {
+    _restoreSavedChannels: function(account) {
         let settings = new Gio.Settings({ schema: 'org.gnome.polari' });
         let savedChannels = settings.get_value('saved-channel-list').deep_unpack();
         for (let i = 0; i < savedChannels.length; i++) {
@@ -116,7 +124,8 @@ const _ChatroomManager = new Lang.Class({
             for (let prop in serializedChannel)
                 serializedChannel[prop] = serializedChannel[prop].deep_unpack();
 
-            this._restoreChannel(serializedChannel);
+            if (account == null || serializedChannel.account == account.object_path)
+                this._restoreChannel(serializedChannel);
         }
     },
 


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