[polari] app: Change how channel saving is done



commit 03a7179a06cbf434081d0ecb3bdd498430163625
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Aug 1 16:41:08 2013 +0200

    app: Change how channel saving is done
    
    Instead of dumping the list of open channels to gsettings on shutdown,
    track channel additions/removals that are due to user interaction, and
    save those.

 src/application.js     |   40 +++++++++++++++++++++++++++++++++++++++-
 src/chatroomManager.js |   19 -------------------
 2 files changed, 39 insertions(+), 20 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index ba5c18b..4aa0877 100644
--- a/src/application.js
+++ b/src/application.js
@@ -53,8 +53,10 @@ const Application = new Lang.Class({
 
         this._chatroomManager = ChatroomManager.getDefault();
         this._accountsMonitor = AccountsMonitor.getDefault();
-        this.pasteManager = new PasteManager.PasteManager();
 
+        this._settings = new Gio.Settings({ schema: 'org.gnome.polari' });
+
+        this.pasteManager = new PasteManager.PasteManager();
         this.notificationQueue = new AppNotifications.NotificationQueue();
         this.commandOutputQueue = new AppNotifications.CommandOutputQueue();
 
@@ -216,6 +218,39 @@ const Application = new Lang.Class({
         log('Activated action "Message user"');
     },
 
+    _addSavedChannel: function(account, channel) {
+        let savedChannels = this._settings.get_value('saved-channel-list').deep_unpack();
+        let savedChannel = {
+            account: GLib.Variant.new('s', account.get_object_path()),
+            channel: GLib.Variant.new('s', channel)
+        };
+        for (let i = 0; i < savedChannels.length; i++)
+            if (savedChannels[i].account.equal(savedChannel.account) &&
+                savedChannels[i].channel.equal(savedChannel.channel))
+                return;
+        savedChannels.push(savedChannel);
+        this._settings.set_value('saved-channel-list',
+                                 GLib.Variant.new('aa{sv}', savedChannels));
+    },
+
+    _removeSavedChannel: function(account, channel) {
+        let savedChannels = this._settings.get_value('saved-channel-list').deep_unpack();
+        let savedChannel = {
+            account: GLib.Variant.new('s', account.get_object_path()),
+            channel: GLib.Variant.new('s', channel)
+        };
+        let i;
+        for (i = 0; i < savedChannels.length; i++)
+            if (savedChannels[i].account.equal(savedChannel.account) &&
+                savedChannels[i].channel.equal(savedChannel.channel))
+                break;
+        if (!savedChannels[i])
+            return;
+        savedChannels.splice(i, 1);
+        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);
@@ -264,6 +299,7 @@ const Application = new Lang.Class({
 
         if (requestData.retry > 0)
             this._updateAccountName(account, requestData.originalNick, null);
+        this._addSavedChannel(account, requestData.target);
     },
 
     _onJoinRoom: function(action, parameter) {
@@ -296,6 +332,8 @@ const Application = new Lang.Class({
                     logError(e, 'Failed to leave channel');
                 }
             }));
+        this._removeSavedChannel(room.channel.connection.get_account(),
+                                 room.channel.identifier);
     },
 
     _onLeaveCurrentRoom: function() {
diff --git a/src/chatroomManager.js b/src/chatroomManager.js
index 06d91e0..cc331ad 100644
--- a/src/chatroomManager.js
+++ b/src/chatroomManager.js
@@ -35,25 +35,12 @@ const _ChatroomManager = new Lang.Class({
     },
 
     _onPrepareShutdown: function() {
-        this._app.hold();
-        let savedChannels = [];
-
         for (let id in this._rooms) {
             let room = this._rooms[id];
 
             if (room.channel.get_invalidated())
                 continue;
 
-            if (!room.channel.has_interface(Tp.IFACE_CHANNEL_INTERFACE_GROUP))
-                continue;
-
-            let account = room.channel.connection.get_account();
-            let serializedChannel = {
-                account: GLib.Variant.new('s', account.get_object_path()),
-                channel: GLib.Variant.new('s', room.channel.identifier)
-            };
-            savedChannels.push(serializedChannel);
-
             this._app.hold();
             room.channel.connect('invalidated', Lang.bind(this,
                 function() {
@@ -61,12 +48,6 @@ const _ChatroomManager = new Lang.Class({
                 }));
             room.channel.leave_async(Tp.ChannelGroupChangeReason.NONE, '', null);
         }
-
-        let settings = new Gio.Settings({ schema: 'org.gnome.polari' });
-        settings.set_value('saved-channel-list',
-                           GLib.Variant.new('aa{sv}', savedChannels));
-
-        this._app.release();
     },
 
     _onPrepared: function(am, res) {


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