[polari/wip/fmuellner/combined-gsoc: 111/137] getNotifyActionName() now returns the full name, and track/untrack functions are cleaner



commit 80c02dd54edb839af1ef89e5b0ffb724b5d75773
Author: raresv <rares visalom gmail com>
Date:   Thu Jul 21 04:46:13 2016 +0300

    getNotifyActionName() now returns the full name, and track/untrack functions are cleaner

 src/userList.js    |   12 +-----------
 src/userTracker.js |   47 +++++++++++++++++++++++++++++++++--------------
 2 files changed, 34 insertions(+), 25 deletions(-)
---
diff --git a/src/userList.js b/src/userList.js
index c98fb87..af9634e 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -394,24 +394,14 @@ const UserPopover = new Lang.Class({
 
         let baseNick = Polari.util_get_basenick(nickname);
 
-        /* Seeing this code, I think getNotifyActionName() should maybe
-         * return the full name - it's a bit of an implementation detail
-         * that the action is added to the application ... */
-        let actionName  = this._userTracker.getNotifyActionName(this._nickname);
-
-        /* As I generally try to keep lines within the 80 character limit,
-         * I'll throw in:
         let actionName = this._userTracker.getNotifyActionName(this._nickname);
         this._notifyButton.action_name = actionName;
-         * as suggestion - the button property and tracker method name already
-         * have 'notify' in there, no need to repeat that over and over */
-        this._notifyButton.action_name = 'app.' + actionName;
 
         this._roomStatusChangedId =
             this._userTracker.watchRoomStatus(this._room, this._nickname,
                                         Lang.bind(this, this._onNickStatusChanged));
 
-        this._globalStatusChangedId = this._userTracker.connect("status-changed::"+this._nickname, 
Lang.bind(this, this._updateContents));
+        this._globalStatusChangedId = this._userTracker.connect("status-changed::" + baseNick, 
Lang.bind(this, this._updateContents));
 
         this._updateContents();
 
diff --git a/src/userTracker.js b/src/userTracker.js
index 9389088..17affad 100644
--- a/src/userTracker.js
+++ b/src/userTracker.js
@@ -209,16 +209,12 @@ const UserTracker = new Lang.Class({
         if (this._pushMember(map, baseNick, member) == 1) {
             this.emit("status-changed::" + baseNick, member.alias, status);
 
-            let notifyActionName = this.getNotifyActionName(member.alias);
-            let notifyAction = this._app.lookup_action(notifyActionName);
+            let notifyAction = this._app.lookup_action(this._getNotifyActionName(member.alias));
 
-            if (notifyAction.get_state().get_boolean()) {
+            if (this._shouldNotifyNick(member.alias))
                 this._emitNotification(room, member);
-                /*change state so that the button is not pressed if it reappears again*/
-                notifyAction.change_state(GLib.Variant.new('b', false));
-            }
 
-            notifyAction.enabled = false;
+            this._setNotifyActionEnabled(member.alias, false);
         }
 
         let roomMap = this._roomMapping.get(room)._contactMapping;
@@ -249,10 +245,9 @@ const UserTracker = new Lang.Class({
             }
             this.emit("contacts-changed::" + baseNick, member.alias);
 
-            let notifyActionName = this.getNotifyActionName(member.alias);
-            let notifyAction = this._app.lookup_action(notifyActionName);
+            let notifyAction = this._app.lookup_action(this._getNotifyActionName(member.alias));
 
-            notifyAction.enabled = true;
+            this._setNotifyActionEnabled(member.alias, true);
         }
 
         let roomMap = this._roomMapping.get(room)._contactMapping;
@@ -345,17 +340,41 @@ const UserTracker = new Lang.Class({
         let baseNick = Polari.util_get_basenick(member.alias);
     },
 
+    _shouldNotifyNick: function(nickName) {
+        let actionName = this._getNotifyActionName(nickName);
+        let state = this._app.get_action_state(actionName);
+        return state ? state.get_boolean()
+                     : false;
+    },
+
+    _setNotifyActionEnabled: function(nickName, enabled) {
+        let name = this._getNotifyActionName(nickName);
+        let action = this._app.lookup_action(name);
+        if (action)
+            action.enabled = enabled;
+    },
+
+    _getNotifyActionName: function(nickName) {
+        return 'notify-user-' +
+               this._account.get_path_suffix() + '-' +
+               Polari.util_get_basenick(nickName);
+    },
+
     getNotifyActionName: function(nickName) {
-        let name = 'notify-user-' +
-                   this._account.get_path_suffix() + '-' +
-                   Polari.util_get_basenick(nickName);
+        let name = this._getNotifyActionName(nickName);
 
         if (!this._app.lookup_action(name)) {
             let state = new GLib.Variant('b', false);
             let action = new Gio.SimpleAction({ name: name, state: state });
+
+            action.connect('notify::enabled', () => {
+                if (!action.enabled)
+                    action.change_state(GLib.Variant.new('b', false));
+            });
+
             this._app.add_action(action);
         }
 
-        return name;
+        return 'app.' + name;
     }
 });


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