[polari] app: Automatically change to nominal nick when it becomes available
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] app: Automatically change to nominal nick when it becomes available
- Date: Tue, 25 Jul 2017 08:11:17 +0000 (UTC)
commit 2a9c39d6f8802c1ee24b91a927d829c1c6936325
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Oct 24 16:00:07 2013 +0100
app: Automatically change to nominal nick when it becomes available
If a connection fails because the chosen nick is already in use, we
automatically retry with an appended underscore. Usually the reason
for this error is an unclean disconnect that leaves the nick from the
previous connection in zombie state until it times out - to get back
to the nominal nick, the user currently has to monitor the chat log
for the zombie timing out and manually change the nickname. We can
do better than that and use our user tracking to determine when the
nominal nick becomes available and change the nickname automatically
if there wasn't a user requested change in the meantime.
https://bugzilla.gnome.org/show_bug.cgi?id=710731
src/application.js | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index f25a30e..c1ce3ca 100644
--- a/src/application.js
+++ b/src/application.js
@@ -38,6 +38,7 @@ var Application = new Lang.Class({
GLib.set_application_name('Polari');
GLib.set_prgname('org.gnome.Polari');
this._retryData = new Map();
+ this._nickTrackData = new Map();
this._demons = [];
this.add_main_option('start-client', 0,
@@ -80,6 +81,7 @@ var Application = new Lang.Class({
account.set_nickname_async(nick, (a, res) => {
account.set_nickname_finish(res);
});
+ this._untrackNominalNick(account);
},
_checkService: function(conn, name, opath, iface) {
@@ -439,6 +441,40 @@ var Application = new Lang.Class({
this._maybePresent(time);
},
+ _trackNominalNick: function(account) {
+ if (this._nickTrackData.has(account))
+ return;
+
+ let nominalNick = this._getTrimmedAccountName(account);
+ let baseNick = Polari.util_get_basenick(nominalNick);
+
+ let tracker = this._userStatusMonitor.getUserTrackerForAccount(account);
+ let contactsChangedId = tracker.connect('contacts-changed::' + baseNick,
+ (t, nick) => {
+ if (nick != nominalNick)
+ return;
+
+ let contact = tracker.lookupContact(nick);
+ if (contact != null && contact.alias == nick)
+ return;
+
+ this._untrackNominalNick(account);
+ account.set_nickname_async(nominalNick, (a, res) => {
+ a.set_nickname_finish(res);
+ });
+ });
+ this._nickTrackData.set(account, { tracker, contactsChangedId });
+ },
+
+ _untrackNominalNick: function(account) {
+ let data = this._nickTrackData.get(account);
+ if (!data)
+ return;
+
+ data.tracker.disconnect(data.contactsChangedId);
+ this._nickTrackData.delete(account);
+ },
+
_ensureRetryData: function(account) {
let data = this._retryData.get(account.object_path);
if (data)
@@ -489,6 +525,8 @@ var Application = new Lang.Class({
if (retryData.retry++ >= MAX_RETRIES)
return false;
+ this._trackNominalNick(account);
+
let oldParams = account.dup_parameters_vardict().deep_unpack();
let nick = oldParams['account'].deep_unpack();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]