Commit 79060c28 authored by Florian Müllner's avatar Florian Müllner
Browse files

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
parent fcff3a7b
......@@ -184,10 +184,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);
});
......@@ -196,7 +194,7 @@ const TelepathyClient = new Lang.Class({
});
this._accountsMonitor.enabledAccounts.forEach(a => {
if (a.connection)
this._connectRooms(a);
this._onAccountStatusChanged(this._accountsMonitor, a);
else
this._connectAccount(a);
});
......@@ -209,6 +207,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;
......@@ -266,6 +276,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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment