[polari/wip/fmuellner/nickserv: 24/29] app: Add 'save-identify-password' action



commit d5e1e50f36882badfabccfeaf104c158a3a98dfe
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Aug 3 02:14:13 2016 +0200

    app: Add 'save-identify-password' action
    
    Implement saving of cached "identify" parameters and expose a
    corresponding action, so the components that ask for user
    confirmation can actually work as promised :-)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709982

 src/application.js     |    2 ++
 src/telepathyClient.js |   31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 334c608..694db37 100644
--- a/src/application.js
+++ b/src/application.js
@@ -78,6 +78,8 @@ const Application = new Lang.Class({
           { name: 'edit-connection',
             activate: Lang.bind(this, this._onEditConnection),
             parameter_type: GLib.VariantType.new('o') },
+          { name: 'save-identify-password',
+            parameter_type: GLib.VariantType.new('o') },
           { name: 'help',
             activate: Lang.bind(this, this._onShowHelp),
             accels: ['F1'] },
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index 7be68b8..b93fcd5 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -151,6 +151,8 @@ const TelepathyClient = new Lang.Class({
               handler: Lang.bind(this, this._onReconnectAccountActivated) },
             { name: 'authenticate-account',
               handler: Lang.bind(this, this._onAuthenticateAccountActivated) },
+            { name: 'save-identify-password',
+              handler: Lang.bind(this, this._onSaveIdentifyPasswordActivated) }
         ];
         actions.forEach(a => {
             this._app.lookup_action(a.name).connect('activate', a.handler);
@@ -337,6 +339,35 @@ const TelepathyClient = new Lang.Class({
         });
     },
 
+    _onSaveIdentifyPasswordActivated: function(action, parameter) {
+        let accountPath = parameter.deep_unpack();
+        let account = this._accountsMonitor.lookupAccount(accountPath);
+        if (!account)
+            return;
+
+        let data = this._pendingBotPasswords.get(account.object_path);
+        if (!data)
+            return;
+
+        Utils.storeIdentifyPassword(account, data.password, (res) => {
+            if (res)
+                this._saveIdentifySettings(account, data);
+
+            this._pendingBotPasswords.delete(account.object_path);
+        });
+    },
+
+    _saveIdentifySettings: function(account, data) {
+        let settings = this._accountsMonitor.getAccountSettings(account);
+
+        if (data.botname == 'NickServ')
+            settings.reset('identify-botname');
+        else
+            settings.set_string('identify-botname', data.botname);
+
+        settings.set_string('identify-username', data.username);
+    },
+
     _isAuthChannel: function(channel) {
         return channel.channel_type == Tp.IFACE_CHANNEL_TYPE_SERVER_AUTHENTICATION;
     },


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