From 8b9efb461e5711b706bc7fb6772890462869a57d Mon Sep 17 00:00:00 2001
From: howard-stearns <howard.stearns@gmail.com>
Date: Wed, 23 Nov 2016 10:22:24 -0800
Subject: [PATCH 1/2] bubble state

---
 libraries/networking/src/NodeList.cpp         |  6 +++++
 libraries/networking/src/NodeList.h           |  5 ++--
 .../src/UsersScriptingInterface.cpp           |  1 +
 .../src/UsersScriptingInterface.h             |  1 +
 scripts/system/bubble.js                      | 26 ++++++++-----------
 5 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp
index 86b9bc1794..d960fb6db9 100644
--- a/libraries/networking/src/NodeList.cpp
+++ b/libraries/networking/src/NodeList.cpp
@@ -886,3 +886,9 @@ void NodeList::muteNodeBySessionID(const QUuid& nodeID) {
 
     }
 }
+
+void NodeList::toggleIgnoreRadius() {
+    bool isIgnored = !getIgnoreRadiusEnabled();
+    ignoreNodesInRadius(getIgnoreRadius(), isIgnored);
+    emit ignoreRadiusEnabledChanged(isIgnored);
+}
\ No newline at end of file
diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h
index f30283f3c2..c453dbb766 100644
--- a/libraries/networking/src/NodeList.h
+++ b/libraries/networking/src/NodeList.h
@@ -74,7 +74,7 @@ public:
     void ignoreNodesInRadius(float radiusToIgnore, bool enabled = true);
     float getIgnoreRadius() const { return _ignoreRadius.get(); }
     bool getIgnoreRadiusEnabled() const { return _ignoreRadiusEnabled.get(); }
-    void toggleIgnoreRadius() { ignoreNodesInRadius(getIgnoreRadius(), !getIgnoreRadiusEnabled()); }
+    void toggleIgnoreRadius();
     void enableIgnoreRadius() { ignoreNodesInRadius(getIgnoreRadius(), true); }
     void disableIgnoreRadius() { ignoreNodesInRadius(getIgnoreRadius(), false); }
     void ignoreNodeBySessionID(const QUuid& nodeID);
@@ -108,6 +108,7 @@ signals:
     void limitOfSilentDomainCheckInsReached();
     void receivedDomainServerList();
     void ignoredNode(const QUuid& nodeID);
+    void ignoreRadiusEnabledChanged(bool isIgnored);
 
 private slots:
     void stopKeepalivePingTimer();
@@ -154,7 +155,7 @@ private:
     tbb::concurrent_unordered_set<QUuid, UUIDHasher> _ignoredNodeIDs;
 
     void sendIgnoreRadiusStateToNode(const SharedNodePointer& destinationNode);
-    Setting::Handle<bool> _ignoreRadiusEnabled { "IgnoreRadiusEnabled", false };
+    Setting::Handle<bool> _ignoreRadiusEnabled { "IgnoreRadiusEnabled", true };
     Setting::Handle<float> _ignoreRadius { "IgnoreRadius", 1.0f };
 
 #if (PR_BUILD || DEV_BUILD)
diff --git a/libraries/script-engine/src/UsersScriptingInterface.cpp b/libraries/script-engine/src/UsersScriptingInterface.cpp
index c809617995..368b7f3985 100644
--- a/libraries/script-engine/src/UsersScriptingInterface.cpp
+++ b/libraries/script-engine/src/UsersScriptingInterface.cpp
@@ -17,6 +17,7 @@ UsersScriptingInterface::UsersScriptingInterface() {
     // emit a signal when kick permissions have changed
     auto nodeList = DependencyManager::get<NodeList>();
     connect(nodeList.data(), &LimitedNodeList::canKickChanged, this, &UsersScriptingInterface::canKickChanged);
+    connect(nodeList.data(), &NodeList::ignoreRadiusEnabledChanged, this, &UsersScriptingInterface::ignoreRadiusEnabledChanged);
 }
 
 void UsersScriptingInterface::ignore(const QUuid& nodeID) {
diff --git a/libraries/script-engine/src/UsersScriptingInterface.h b/libraries/script-engine/src/UsersScriptingInterface.h
index 07398558e5..c621fd9284 100644
--- a/libraries/script-engine/src/UsersScriptingInterface.h
+++ b/libraries/script-engine/src/UsersScriptingInterface.h
@@ -100,6 +100,7 @@ public slots:
 
 signals:
     void canKickChanged(bool canKick);
+    void ignoreRadiusEnabledChanged(bool isEnabled);
 };
 
 
diff --git a/scripts/system/bubble.js b/scripts/system/bubble.js
index ba317ecdca..408f3acffa 100644
--- a/scripts/system/bubble.js
+++ b/scripts/system/bubble.js
@@ -25,34 +25,30 @@ function buttonImageURL() {
     return TOOLS_PATH + 'bubble.svg';
 }
 
-var bubbleActive = Users.getIgnoreRadiusEnabled();
+function onBubbleToggled() {
+    var bubbleActive = Users.getIgnoreRadiusEnabled();
+    button.writeProperty('buttonState', bubbleActive ? 0 : 1);
+    button.writeProperty('defaultState', bubbleActive ? 0 : 1);
+    button.writeProperty('hoverState', bubbleActive ? 2 : 3);
+}
 
 // setup the mod button and add it to the toolbar
 var button = toolbar.addButton({
     objectName: 'bubble',
     imageURL: buttonImageURL(),
     visible: true,
-    buttonState: bubbleActive ? 0 : 1,
-    defaultState: bubbleActive ? 0 : 1,
-    hoverState: bubbleActive ? 2 : 3,
     alpha: 0.9
 });
+onBubbleToggled();
 
-
-// handle clicks on the toolbar button
-function buttonClicked(){
-    Users.toggleIgnoreRadius();
-    bubbleActive = Users.getIgnoreRadiusEnabled();
-    button.writeProperty('buttonState', bubbleActive ? 0 : 1);
-    button.writeProperty('defaultState', bubbleActive ? 0 : 1);
-    button.writeProperty('hoverState', bubbleActive ? 2 : 3);
-}
-
-button.clicked.connect(buttonClicked);
+button.clicked.connect(Users.toggleIgnoreRadius);
+Users.ignoreRadiusEnabledChanged.connect(onBubbleToggled);
 
 // cleanup the toolbar button and overlays when script is stopped
 Script.scriptEnding.connect(function() {
     toolbar.removeButton('bubble');
+    button.clicked.disconnect(Users.toggleIgnoreRadius);
+    Users.ignoreRadiusEnabledChanged.disconnect(onBubbleToggled);
 });
 
 }()); // END LOCAL_SCOPE

From b37feb20deb15c0c01ef8f281ee7d7742078bc9e Mon Sep 17 00:00:00 2001
From: howard-stearns <howard.stearns@gmail.com>
Date: Wed, 23 Nov 2016 11:23:06 -0800
Subject: [PATCH 2/2] signal from ignoreNodesInRadius

---
 libraries/networking/src/NodeList.cpp | 10 ++++------
 libraries/networking/src/NodeList.h   |  2 +-
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp
index d960fb6db9..dfb65a70ec 100644
--- a/libraries/networking/src/NodeList.cpp
+++ b/libraries/networking/src/NodeList.cpp
@@ -751,6 +751,7 @@ bool NodeList::sockAddrBelongsToDomainOrNode(const HifiSockAddr& sockAddr) {
 }
 
 void NodeList::ignoreNodesInRadius(float radiusToIgnore, bool enabled) {
+    bool isEnabledChange = _ignoreRadiusEnabled.get() != enabled;
     _ignoreRadiusEnabled.set(enabled);
     _ignoreRadius.set(radiusToIgnore);
 
@@ -759,6 +760,9 @@ void NodeList::ignoreNodesInRadius(float radiusToIgnore, bool enabled) {
     }, [this](const SharedNodePointer& destinationNode) {
         sendIgnoreRadiusStateToNode(destinationNode);
     });
+    if (isEnabledChange) {
+        emit ignoreRadiusEnabledChanged(enabled);
+    }
 }
 
 void NodeList::sendIgnoreRadiusStateToNode(const SharedNodePointer& destinationNode) {
@@ -886,9 +890,3 @@ void NodeList::muteNodeBySessionID(const QUuid& nodeID) {
 
     }
 }
-
-void NodeList::toggleIgnoreRadius() {
-    bool isIgnored = !getIgnoreRadiusEnabled();
-    ignoreNodesInRadius(getIgnoreRadius(), isIgnored);
-    emit ignoreRadiusEnabledChanged(isIgnored);
-}
\ No newline at end of file
diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h
index c453dbb766..3bf44bbdf4 100644
--- a/libraries/networking/src/NodeList.h
+++ b/libraries/networking/src/NodeList.h
@@ -74,7 +74,7 @@ public:
     void ignoreNodesInRadius(float radiusToIgnore, bool enabled = true);
     float getIgnoreRadius() const { return _ignoreRadius.get(); }
     bool getIgnoreRadiusEnabled() const { return _ignoreRadiusEnabled.get(); }
-    void toggleIgnoreRadius();
+    void toggleIgnoreRadius() { ignoreNodesInRadius(getIgnoreRadius(), !getIgnoreRadiusEnabled()); }
     void enableIgnoreRadius() { ignoreNodesInRadius(getIgnoreRadius(), true); }
     void disableIgnoreRadius() { ignoreNodesInRadius(getIgnoreRadius(), false); }
     void ignoreNodeBySessionID(const QUuid& nodeID);