[polari] app: Delete saved channels for deleted accounts



commit eaebaafa3069d1e164c7b6404f296b7770b4074d
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Dec 12 12:10:54 2013 +0000

    app: Delete saved channels for deleted accounts
    
    When an account is removed, its identifier may be reused for a
    completely different connection. If that happens, it is rather
    confusing to have "foreign" rooms (including history) restored.
    There is nothing we can do when this happens behind our back,
    but let's at least deal with it in case we can.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=715025

 src/application.js |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index bc2603d..0b5811c 100644
--- a/src/application.js
+++ b/src/application.js
@@ -61,6 +61,11 @@ const Application = new Lang.Class({
         this._chatroomManager = ChatroomManager.getDefault();
         this._accountsMonitor = AccountsMonitor.getDefault();
 
+        this._accountsMonitor.connect('account-removed', Lang.bind(this,
+            function(am, account) {
+                this._removeSavedChannelsForAccount(account);
+            }));
+
         this._settings = new Gio.Settings({ schema: 'org.gnome.polari' });
 
         this.pasteManager = new PasteManager.PasteManager();
@@ -274,6 +279,17 @@ const Application = new Lang.Class({
                                  GLib.Variant.new('aa{sv}', savedChannels));
     },
 
+    _removeSavedChannelsForAccount: function(account) {
+        let savedChannels = this._settings.get_value('saved-channel-list').deep_unpack();
+        let accountPath = GLib.Variant.new('s', account.get_object_path());
+
+        let savedChannels = savedChannels.filter(function(a) {
+            return !a.account.equal(accountPath);
+        });
+        this._settings.set_value('saved-channel-list',
+                                 GLib.Variant.new('aa{sv}', savedChannels));
+    },
+
     _updateAccountName: function(account, name, callback) {
         let sv = { account: GLib.Variant.new('s', name) };
         let asv = GLib.Variant.new('a{sv}', sv);
@@ -285,8 +301,14 @@ const Application = new Lang.Class({
         let factory = Tp.AccountManager.dup().get_factory();
         let account = factory.ensure_account(accountPath, []);
 
-        if (!account.enabled)
+        if (!account.enabled) {
+            // if we are requesting a channel for a disabled account, we
+            // are restoring saved channels; if the account has also never
+            // been online, it was removed since the channel was saved
+            if (!account.has_been_online)
+                this._removeSavedChannelsForAccount(account);
             return;
+        }
 
         let roomId = Polari.create_room_id(account,  targetId, targetType);
 


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