[polari/wip/fmuellner/nickserv: 20/20] telepathyClient: Identify with NickServ when connecting



commit 031f21859fa88aad0d512fd3fd55f612f0114236
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Aug 1 20:42:40 2016 +0200

    telepathyClient: Identify with NickServ when connecting
    
    And finally, we can use saved NickServ credentials to automatically
    identify the user before joining rooms.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709982

 src/telepathyClient.js |   42 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/src/telepathyClient.js b/src/telepathyClient.js
index f1e4eb8..cd3810c 100644
--- a/src/telepathyClient.js
+++ b/src/telepathyClient.js
@@ -181,10 +181,8 @@ const TelepathyClient = new Lang.Class({
         });
         this.register();
 
-        this._accountsMonitor.connect('account-status-changed', Lang.bind(this, function(monitor, account) {
-            if (account.connection_status == Tp.ConnectionStatus.CONNECTED)
-                this._connectRooms(account);
-        }));
+        this._accountsMonitor.connect('account-status-changed',
+                                      Lang.bind(this ,this._onAccountStatusChanged));
         this._accountsMonitor.connect('account-added', (mon, account) => {
             this._connectAccount(account);
         });
@@ -206,6 +204,18 @@ const TelepathyClient = new Lang.Class({
         });
     },
 
+    _onAccountStatusChanged: function(mon, account) {
+        if (account.connection_status != Tp.ConnectionStatus.CONNECTED)
+            return;
+
+        Utils.lookupIdentifyPassword(account, (password) => {
+            if (password)
+                this._sendIdentify(account, password);
+            else
+                this._connectRooms(account);
+        });
+    },
+
     _connectAccount: function(account) {
         let presence = Tp.ConnectionPresenceType.AVAILABLE;
         let msg = account.requested_status_message;
@@ -263,6 +273,30 @@ const TelepathyClient = new Lang.Class({
             });
     },
 
+    _sendIdentify: function(account, password) {
+        let settings = this._accountsMonitor.getAccountSettings(account);
+
+        let params = account.dup_parameters_vardict().deep_unpack();
+        let username = settings.get_string('identify-username') ||
+                       params.username.deep_unpack();
+        let contactName = settings.get_string('identify-botname');
+        this._requestChannel(account, Tp.HandleType.CONTACT, contactName,
+            (channel) => {
+                if (!channel)
+                    return;
+
+                let room = this._roomManager.lookupRoomByChannel(channel);
+                room.send_identify_message_async(username, password, (r, res) => {
+                    try {
+                        r.send_identify_message_finish(res);
+                    } catch(e) {
+                        log('Failed to send identify message: ' + e.message);
+                    }
+                    this._connectRooms(account);
+                });
+            });
+    },
+
     _sendMessage: function(channel, message) {
         if (!message || !channel)
             return;


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