From 9f2b6dc40b82f2797b6cfc20d8ac08c4f99403f9 Mon Sep 17 00:00:00 2001
From: howard-stearns <howard.stearns@gmail.com>
Date: Wed, 16 Nov 2016 12:53:57 -0800
Subject: [PATCH 1/4] location cleanup

---
 interface/resources/qml/AddressBarDialog.qml | 4 ++--
 libraries/networking/src/AddressManager.h    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml
index 941099b7cc..38250b8be7 100644
--- a/interface/resources/qml/AddressBarDialog.qml
+++ b/interface/resources/qml/AddressBarDialog.qml
@@ -370,7 +370,7 @@ Window {
         if (place.action === 'snapshot') {
             return true;
         }
-        return (place.place_name !== AddressManager.hostname); // Not our entry, but do show other entry points to current domain.
+        return (place.place_name !== AddressManager.placename); // Not our entry, but do show other entry points to current domain.
         // could also require right protocolVersion
     }
     function getUserStoryPage(pageNumber, cb) { // cb(error) after all pages of domain data have been added to model
@@ -436,7 +436,7 @@ Window {
             notice.text = AddressManager.isConnected ? "Your location:" : "Not Connected";
             notice.color = AddressManager.isConnected ? hifiStyleConstants.colors.baseGrayHighlight : hifiStyleConstants.colors.redHighlight;
             // Display hostname, which includes ip address, localhost, and other non-placenames.
-            location.text = (AddressManager.hostname || '') + (AddressManager.pathname ? AddressManager.pathname.match(/\/[^\/]+/)[0] : '');
+            location.text = (AddressManager.placename || AddressManager.hostname || '') + (AddressManager.pathname ? AddressManager.pathname.match(/\/[^\/]+/)[0] : '');
         }
     }
 
diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h
index f979002f7a..0c46f9688b 100644
--- a/libraries/networking/src/AddressManager.h
+++ b/libraries/networking/src/AddressManager.h
@@ -35,7 +35,7 @@ class AddressManager : public QObject, public Dependency {
     Q_OBJECT
     SINGLETON_DEPENDENCY
     Q_PROPERTY(bool isConnected READ isConnected)
-    Q_PROPERTY(QUrl href READ currentAddress)
+    Q_PROPERTY(QUrl href READ currentShareableAddress)
     Q_PROPERTY(QString protocol READ getProtocol)
     Q_PROPERTY(QString hostname READ getHost)
     Q_PROPERTY(QString pathname READ currentPath)
@@ -67,7 +67,7 @@ public:
     QString currentFacingPath() const;
 
     const QUuid& getRootPlaceID() const { return _rootPlaceID; }
-    const QString& getPlaceName() const { return _placeName; }
+    const QString& getPlaceName() const { return _shareablePlaceName.isEmpty() ? _placeName : _shareablePlaceName; }
 
     const QString& getHost() const { return _host; }
 

From f1806eb64917687924aceed7165f42b5500a32ac Mon Sep 17 00:00:00 2001
From: howard-stearns <howard.stearns@gmail.com>
Date: Fri, 18 Nov 2016 17:05:14 -0800
Subject: [PATCH 2/4] server protocols

---
 interface/resources/qml/AddressBarDialog.qml |  3 +++
 libraries/networking/src/AddressManager.cpp  |  4 ++++
 libraries/networking/src/AddressManager.h    |  2 ++
 scripts/system/snapshot.js                   | 22 +++++++++++++++++++-
 4 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml
index 38250b8be7..172245876a 100644
--- a/interface/resources/qml/AddressBarDialog.qml
+++ b/interface/resources/qml/AddressBarDialog.qml
@@ -375,7 +375,10 @@ Window {
     }
     function getUserStoryPage(pageNumber, cb) { // cb(error) after all pages of domain data have been added to model
         var options = [
+            'now=' + new Date().toISOString(),
             'include_actions=snapshot,concurrency',
+            'restriction=' + (Account.isLoggedIn() ? 'open,hifi' : 'open'),
+            'require_online=true',
             'protocol=' + encodeURIComponent(AddressManager.protocolVersion()),
             'page=' + pageNumber
         ];
diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp
index 4089fd4966..05210012ba 100644
--- a/libraries/networking/src/AddressManager.cpp
+++ b/libraries/networking/src/AddressManager.cpp
@@ -750,6 +750,10 @@ void AddressManager::copyPath() {
     QApplication::clipboard()->setText(currentPath());
 }
 
+QString AddressManager::getDomainId() const {
+    return DependencyManager::get<NodeList>()->getDomainHandler().getUUID().toString();
+}
+
 void AddressManager::handleShareableNameAPIResponse(QNetworkReply& requestReply) {
     // make sure that this response is for the domain we're currently connected to
     auto domainID = DependencyManager::get<NodeList>()->getDomainHandler().getUUID();
diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h
index 0c46f9688b..366fc5dfab 100644
--- a/libraries/networking/src/AddressManager.h
+++ b/libraries/networking/src/AddressManager.h
@@ -40,6 +40,7 @@ class AddressManager : public QObject, public Dependency {
     Q_PROPERTY(QString hostname READ getHost)
     Q_PROPERTY(QString pathname READ currentPath)
     Q_PROPERTY(QString placename READ getPlaceName)
+    Q_PROPERTY(QString domainId READ getDomainId)
 public:
     Q_INVOKABLE QString protocolVersion();
     using PositionGetter = std::function<glm::vec3()>;
@@ -68,6 +69,7 @@ public:
 
     const QUuid& getRootPlaceID() const { return _rootPlaceID; }
     const QString& getPlaceName() const { return _shareablePlaceName.isEmpty() ? _placeName : _shareablePlaceName; }
+    QString getDomainId() const;
 
     const QString& getHost() const { return _host; }
 
diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js
index 5eebadd02f..daee40d576 100644
--- a/scripts/system/snapshot.js
+++ b/scripts/system/snapshot.js
@@ -124,6 +124,26 @@ function onClicked() {
     }, SNAPSHOT_DELAY);
 }
 
+function isDomainOpen(id) {
+    var request = new XMLHttpRequest();
+    var options = [
+        'now=' + new Date().toISOString(),
+        'include_actions=concurrency',
+        'domain_id=' + id.slice(1, -1),
+        'restriction=open,hifi' // If we're sharing, we're logged in
+        // If we're here, protocol matches, and it is online
+    ];
+    var url = "https://metaverse.highfidelity.com/api/v1/user_stories?" + options.join('&');
+    request.open("GET", url, false);
+    request.send();
+    if (request.status != 200) {
+        return false;
+    }
+    var response = JSON.parse(request.response); // Not parsed for us.
+    return (response.status === 'success') &&
+        response.total_entries;
+}
+
 function resetButtons(path, notify) {
     // show overlays if they were on
     if (resetOverlays) {
@@ -143,7 +163,7 @@ function resetButtons(path, notify) {
     confirmShare([ 
         { localPath: path },
         {
-            canShare: !!location.placename,
+            canShare: !!isDomainOpen(location.domainId),
             openFeedAfterShare: shouldOpenFeedAfterShare()
         }
     ]);

From 066a5181421b1c91d8211b6210f99eaf337ae0ec Mon Sep 17 00:00:00 2001
From: howard-stearns <howard.stearns@gmail.com>
Date: Mon, 21 Nov 2016 13:07:38 -0800
Subject: [PATCH 3/4] expose metaverse url to javascript and use it rather than
 hardcoding

---
 libraries/networking/src/AddressManager.cpp | 5 +++++
 libraries/networking/src/AddressManager.h   | 2 ++
 scripts/system/snapshot.js                  | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp
index 05210012ba..240c722872 100644
--- a/libraries/networking/src/AddressManager.cpp
+++ b/libraries/networking/src/AddressManager.cpp
@@ -24,6 +24,7 @@
 
 #include "AddressManager.h"
 #include "NodeList.h"
+#include "NetworkingConstants.h"
 #include "NetworkLogging.h"
 #include "UserActivityLogger.h"
 #include "udt/PacketHeaders.h"
@@ -754,6 +755,10 @@ QString AddressManager::getDomainId() const {
     return DependencyManager::get<NodeList>()->getDomainHandler().getUUID().toString();
 }
 
+const QUrl AddressManager::getMetaverseServerUrl() const {
+    return NetworkingConstants::METAVERSE_SERVER_URL;
+}
+
 void AddressManager::handleShareableNameAPIResponse(QNetworkReply& requestReply) {
     // make sure that this response is for the domain we're currently connected to
     auto domainID = DependencyManager::get<NodeList>()->getDomainHandler().getUUID();
diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h
index 366fc5dfab..c7d283ad02 100644
--- a/libraries/networking/src/AddressManager.h
+++ b/libraries/networking/src/AddressManager.h
@@ -41,6 +41,7 @@ class AddressManager : public QObject, public Dependency {
     Q_PROPERTY(QString pathname READ currentPath)
     Q_PROPERTY(QString placename READ getPlaceName)
     Q_PROPERTY(QString domainId READ getDomainId)
+    Q_PROPERTY(QUrl metaverseServerUrl READ getMetaverseServerUrl)
 public:
     Q_INVOKABLE QString protocolVersion();
     using PositionGetter = std::function<glm::vec3()>;
@@ -70,6 +71,7 @@ public:
     const QUuid& getRootPlaceID() const { return _rootPlaceID; }
     const QString& getPlaceName() const { return _shareablePlaceName.isEmpty() ? _placeName : _shareablePlaceName; }
     QString getDomainId() const;
+    const QUrl getMetaverseServerUrl() const;
 
     const QString& getHost() const { return _host; }
 
diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js
index 6b8e2b32aa..f6ae6d153d 100644
--- a/scripts/system/snapshot.js
+++ b/scripts/system/snapshot.js
@@ -133,7 +133,7 @@ function isDomainOpen(id) {
         'restriction=open,hifi' // If we're sharing, we're logged in
         // If we're here, protocol matches, and it is online
     ];
-    var url = "https://metaverse.highfidelity.com/api/v1/user_stories?" + options.join('&');
+    var url = location.metaverseServerUrl + "/api/v1/user_stories?" + options.join('&');
     request.open("GET", url, false);
     request.send();
     if (request.status != 200) {

From 2beed7e70b66ded39acc8107741f2cd4d8ccfcd6 Mon Sep 17 00:00:00 2001
From: howard-stearns <howard.stearns@gmail.com>
Date: Mon, 21 Nov 2016 16:22:02 -0800
Subject: [PATCH 4/4] proper include_actions for 'places' tab.

---
 interface/resources/qml/AddressBarDialog.qml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml
index a616b05394..db6b87220d 100644
--- a/interface/resources/qml/AddressBarDialog.qml
+++ b/interface/resources/qml/AddressBarDialog.qml
@@ -438,7 +438,7 @@ Window {
     function getUserStoryPage(pageNumber, cb) { // cb(error) after all pages of domain data have been added to model
         var options = [
             'now=' + new Date().toISOString(),
-            'include_actions=snapshot,concurrency',
+            'include_actions=' + selectedTab.includeActions,
             'restriction=' + (Account.isLoggedIn() ? 'open,hifi' : 'open'),
             'require_online=true',
             'protocol=' + encodeURIComponent(AddressManager.protocolVersion()),