[polari] app: Add setAccountNick() method



commit f320f96425c391c67d6aceaa0a819a220f81bf33
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Jul 20 21:22:31 2017 +0200

    app: Add setAccountNick() method
    
    We currently have no way to differentiate nickname changes from user
    requests from automatic changes (either us appending underscores on
    conflicts, or telepathy syncing the various properties on connection).
    This is something we will need soon, so add a smaller wrapper method
    for use only with user requested nick changes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710731

 src/application.js |    7 +++++++
 src/entryArea.js   |   37 ++++++++++++++-----------------------
 src/ircParser.js   |    8 +-------
 3 files changed, 22 insertions(+), 30 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index ae701f2..f25a30e 100644
--- a/src/application.js
+++ b/src/application.js
@@ -75,6 +75,13 @@ var Application = new Lang.Class({
                this.active_window.active_room == room;
     },
 
+    // Small wrapper to mark user-requested nick changes
+    setAccountNick: function(account, nick) {
+        account.set_nickname_async(nick, (a, res) => {
+            account.set_nickname_finish(res);
+        });
+    },
+
     _checkService: function(conn, name, opath, iface) {
         let flags = Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
                     Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS;
diff --git a/src/entryArea.js b/src/entryArea.js
index c112b3b..e078bde 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -388,29 +388,20 @@ var EntryArea = new Lang.Class({
         this._nickLabel.width_chars = Math.max(nick.length, this._maxNickChars);
         this._nickLabel.label = nick;
 
-        let account = this._room.account;
-        account.set_nickname_async(nick, (a, res) => {
-            try {
-                a.set_nickname_finish(res);
-            } catch(e) {
-                logError(e, "Failed to change nick");
-
-                this._updateNick();
-                return;
-            }
-
-            // TpAccount:nickname is a local property which doesn't
-            // necessarily match the externally visible nick; telepathy
-            // doesn't consider failing to sync the two an error, so
-            // we give the server MAX_NICK_UPDATE_TIME seconds until
-            // we assume failure and revert back to the server nick
-            //
-            // (set_aliases() would do what we want, but it's not
-            // introspected)
-            Mainloop.timeout_add_seconds(MAX_NICK_UPDATE_TIME, () => {
-                this._updateNick();
-                return GLib.SOURCE_REMOVE;
-            });
+        let app = Gio.Application.get_default();
+        app.setAccountNick(this._room.account, nick);
+
+        // TpAccount:nickname is a local property which doesn't
+        // necessarily match the externally visible nick; telepathy
+        // doesn't consider failing to sync the two an error, so
+        // we give the server MAX_NICK_UPDATE_TIME seconds until
+        // we assume failure and revert back to the server nick
+        //
+        // (set_aliases() would do what we want, but it's not
+        // introspected)
+        Mainloop.timeout_add_seconds(MAX_NICK_UPDATE_TIME, () => {
+            this._updateNick();
+            return GLib.SOURCE_REMOVE;
         });
     },
 
diff --git a/src/ircParser.js b/src/ircParser.js
index f1313ff..c3f9a49 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -202,13 +202,7 @@ var IrcParser = new Lang.Class({
                 if (argv.length)
                     log('Excess arguments to NICK command: ' + argv);
 
-                this._room.account.set_nickname_async(nick, (a, res) => {
-                    try {
-                        a.set_nickname_finish(res);
-                    } catch(e) {
-                        logError(e, 'Failed to update nick');
-                    }
-                });
+                this._app.setAccountNick(this._room.account, nick);
                 break;
             }
             case 'PART':


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