mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 07:03:44 +02:00
handle discoverability change in DiscoverabilityManager
This commit is contained in:
parent
0658b54263
commit
6d900d5a40
3 changed files with 76 additions and 32 deletions
|
@ -247,6 +247,7 @@ bool setupEssentials(int& argc, char** argv) {
|
||||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||||
auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
|
auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
|
||||||
#endif
|
#endif
|
||||||
|
auto discoverabilityManager = DependencyManager::set<DiscoverabilityManager>();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,47 +19,72 @@
|
||||||
|
|
||||||
#include "DiscoverabilityManager.h"
|
#include "DiscoverabilityManager.h"
|
||||||
|
|
||||||
|
const Discoverability::Mode DEFAULT_DISCOVERABILITY_MODE = Discoverability::None;
|
||||||
|
|
||||||
|
DiscoverabilityManager::DiscoverabilityManager() :
|
||||||
|
_mode("discoverabilityMode", DEFAULT_DISCOVERABILITY_MODE)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const QString API_USER_LOCATION_PATH = "/api/v1/user/location";
|
const QString API_USER_LOCATION_PATH = "/api/v1/user/location";
|
||||||
|
|
||||||
void DiscoverabilityManager::updateLocation() {
|
void DiscoverabilityManager::updateLocation() {
|
||||||
AccountManager& accountManager = AccountManager::getInstance();
|
if (_mode.get() != Discoverability::None) {
|
||||||
auto addressManager = DependencyManager::get<AddressManager>();
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
auto addressManager = DependencyManager::get<AddressManager>();
|
||||||
|
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
||||||
if (accountManager.isLoggedIn() && domainHandler.isConnected()
|
|
||||||
&& (!addressManager->getRootPlaceID().isNull() || !domainHandler.getUUID().isNull())) {
|
|
||||||
|
|
||||||
// construct a QJsonObject given the user's current address information
|
if (accountManager.isLoggedIn() && domainHandler.isConnected()
|
||||||
QJsonObject rootObject;
|
&& (!addressManager->getRootPlaceID().isNull() || !domainHandler.getUUID().isNull())) {
|
||||||
|
|
||||||
QJsonObject locationObject;
|
|
||||||
|
|
||||||
QString pathString = addressManager->currentPath();
|
|
||||||
|
|
||||||
const QString LOCATION_KEY_IN_ROOT = "location";
|
|
||||||
|
|
||||||
const QString PATH_KEY_IN_LOCATION = "path";
|
|
||||||
locationObject.insert(PATH_KEY_IN_LOCATION, pathString);
|
|
||||||
|
|
||||||
if (!addressManager->getRootPlaceID().isNull()) {
|
|
||||||
const QString PLACE_ID_KEY_IN_LOCATION = "place_id";
|
|
||||||
locationObject.insert(PLACE_ID_KEY_IN_LOCATION,
|
|
||||||
uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID()));
|
|
||||||
|
|
||||||
} else {
|
// construct a QJsonObject given the user's current address information
|
||||||
const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id";
|
QJsonObject rootObject;
|
||||||
locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION,
|
|
||||||
uuidStringWithoutCurlyBraces(domainHandler.getUUID()));
|
QJsonObject locationObject;
|
||||||
|
|
||||||
|
QString pathString = addressManager->currentPath();
|
||||||
|
|
||||||
|
const QString LOCATION_KEY_IN_ROOT = "location";
|
||||||
|
|
||||||
|
const QString PATH_KEY_IN_LOCATION = "path";
|
||||||
|
locationObject.insert(PATH_KEY_IN_LOCATION, pathString);
|
||||||
|
|
||||||
|
if (!addressManager->getRootPlaceID().isNull()) {
|
||||||
|
const QString PLACE_ID_KEY_IN_LOCATION = "place_id";
|
||||||
|
locationObject.insert(PLACE_ID_KEY_IN_LOCATION,
|
||||||
|
uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID()));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id";
|
||||||
|
locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION,
|
||||||
|
uuidStringWithoutCurlyBraces(domainHandler.getUUID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);
|
||||||
|
|
||||||
|
accountManager.authenticatedRequest(API_USER_LOCATION_PATH, QNetworkAccessManager::PutOperation,
|
||||||
|
JSONCallbackParameters(), QJsonDocument(rootObject).toJson());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);
|
qDebug() << "not updating discoverability since it is currently set to none!";
|
||||||
|
|
||||||
accountManager.authenticatedRequest(API_USER_LOCATION_PATH, QNetworkAccessManager::PutOperation,
|
|
||||||
JSONCallbackParameters(), QJsonDocument(rootObject).toJson());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiscoverabilityManager::removeLocation() {
|
void DiscoverabilityManager::removeLocation() {
|
||||||
AccountManager& accountManager = AccountManager::getInstance();
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
accountManager.authenticatedRequest(API_USER_LOCATION_PATH, QNetworkAccessManager::DeleteOperation);
|
accountManager.authenticatedRequest(API_USER_LOCATION_PATH, QNetworkAccessManager::DeleteOperation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DiscoverabilityManager::setDiscoverability(Discoverability::Mode discoverabilityMode) {
|
||||||
|
if (_mode.get() != discoverabilityMode) {
|
||||||
|
|
||||||
|
// update the setting to the new value
|
||||||
|
_mode.set(discoverabilityMode);
|
||||||
|
|
||||||
|
if (_mode.get() == Discoverability::None) {
|
||||||
|
// if we just got set to no discoverability, make sure that we delete our location in DB
|
||||||
|
removeLocation();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -13,6 +13,17 @@
|
||||||
#define hifi_DiscoverabilityManager_h
|
#define hifi_DiscoverabilityManager_h
|
||||||
|
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
|
#include <SettingHandle.h>
|
||||||
|
|
||||||
|
namespace Discoverability {
|
||||||
|
enum Mode {
|
||||||
|
None,
|
||||||
|
Friends,
|
||||||
|
All
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(Discoverability::Mode);
|
||||||
|
|
||||||
class DiscoverabilityManager : public QObject, public Dependency {
|
class DiscoverabilityManager : public QObject, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -20,7 +31,14 @@ class DiscoverabilityManager : public QObject, public Dependency {
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateLocation();
|
void updateLocation();
|
||||||
void removeLocation();
|
void removeLocation();
|
||||||
|
|
||||||
|
void setDiscoverability(Discoverability::Mode discoverabilityMode);
|
||||||
|
|
||||||
|
private:
|
||||||
|
DiscoverabilityManager();
|
||||||
|
|
||||||
|
Setting::Handle<Discoverability::Mode> _mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_DiscoverabilityManager_h
|
#endif // hifi_DiscoverabilityManager_h
|
Loading…
Reference in a new issue