Showing the changes to interface/src/DiscoverabilityManager.cpp (1 of 1 file). Show all
Unified · Split
| @@ -37,72 +37,71 @@ const QString SESSION_ID_KEY = "session_id"; · 36 unmodified lines | ||
| 37 | 37 | void DiscoverabilityManager::updateLocation() { |
| 38 | 38 | AccountManager& accountManager = AccountManager::getInstance(); |
| 39 | 39 | |
| 40 | − if (_mode.get() != Discoverability::None) { | |
| 40 | + if (_mode.get() != Discoverability::None && accountManager.isLoggedIn()) { | |
| 41 | 41 | auto addressManager = DependencyManager::get<AddressManager>(); |
| 42 | 42 | DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler(); |
| 43 | − | |
| 44 | − if (accountManager.isLoggedIn() && domainHandler.isConnected() | |
| 45 | − && (!addressManager->getRootPlaceID().isNull() || !domainHandler.getUUID().isNull())) { | |
| 46 | − | |
| 47 | − // construct a QJsonObject given the user's current address information | |
| 48 | − QJsonObject rootObject; | |
| 49 | − | |
| 50 | − QJsonObject locationObject; | |
| 51 | − | |
| 52 | − QString pathString = addressManager->currentPath(); | |
| 53 | − | |
| 54 | − const QString LOCATION_KEY_IN_ROOT = "location"; | |
| 55 | − | |
| 56 | − const QString PATH_KEY_IN_LOCATION = "path"; | |
| 57 | − locationObject.insert(PATH_KEY_IN_LOCATION, pathString); | |
| 58 | − | |
| 59 | − if (!addressManager->getRootPlaceID().isNull()) { | |
| 60 | − const QString PLACE_ID_KEY_IN_LOCATION = "place_id"; | |
| 61 | − locationObject.insert(PLACE_ID_KEY_IN_LOCATION, | |
| 62 | − uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID())); | |
| 63 | − } | |
| 64 | − | |
| 65 | − if (!domainHandler.getUUID().isNull()) { | |
| 66 | − const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id"; | |
| 67 | − locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, | |
| 68 | − uuidStringWithoutCurlyBraces(domainHandler.getUUID())); | |
| 69 | − } | |
| 70 | − | |
| 71 | − // in case the place/domain isn't in the database, we send the network address and port | |
| 72 | − auto& domainSockAddr = domainHandler.getSockAddr(); | |
| 73 | − const QString NETWORK_ADRESS_KEY_IN_LOCATION = "network_address"; | |
| 74 | − locationObject.insert(NETWORK_ADRESS_KEY_IN_LOCATION, domainSockAddr.getAddress().toString()); | |
| 75 | − | |
| 76 | − const QString NETWORK_ADDRESS_PORT_IN_LOCATION = "network_port"; | |
| 77 | − locationObject.insert(NETWORK_ADDRESS_PORT_IN_LOCATION, domainSockAddr.getPort()); | |
| 78 | − | |
| 79 | − const QString FRIENDS_ONLY_KEY_IN_LOCATION = "friends_only"; | |
| 80 | − locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends)); | |
| 81 | − | |
| 82 | − // if we have a session ID add it now, otherwise add a null value | |
| 83 | − rootObject[SESSION_ID_KEY] = _sessionID.isEmpty() ? QJsonValue() : _sessionID; | |
| 84 | − | |
| 85 | − JSONCallbackParameters callbackParameters; | |
| 86 | − callbackParameters.jsonCallbackReceiver = this; | |
| 87 | − callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse"; | |
| 88 | − | |
| 89 | − // figure out if we'll send a fresh location or just a simple heartbeat | |
| 90 | − auto apiPath = API_USER_HEARTBEAT_PATH; | |
| 91 | − | |
| 92 | − if (locationObject != _lastLocationObject) { | |
| 93 | − // we have a changed location, send it now | |
| 94 | − _lastLocationObject = locationObject; | |
| 95 | − | |
| 96 | − rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); | |
| 97 | − | |
| 98 | − apiPath = API_USER_LOCATION_PATH; | |
| 99 | − } | |
| 100 | − | |
| 101 | − accountManager.sendRequest(apiPath, AccountManagerAuth::Required, | |
| 102 | − QNetworkAccessManager::PutOperation, | |
| 103 | − callbackParameters, QJsonDocument(rootObject).toJson()); | |
| 104 | 43 | |
| 44 | + // construct a QJsonObject given the user's current address information | |
| 45 | + QJsonObject rootObject; | |
| 46 | + | |
| 47 | + QJsonObject locationObject; | |
| 48 | + | |
| 49 | + QString pathString = addressManager->currentPath(); | |
| 50 | + | |
| 51 | + const QString LOCATION_KEY_IN_ROOT = "location"; | |
| 52 | + | |
| 53 | + const QString PATH_KEY_IN_LOCATION = "path"; | |
| 54 | + locationObject.insert(PATH_KEY_IN_LOCATION, pathString); | |
| 55 | + | |
| 56 | + const QString CONNECTED_KEY_IN_LOCATION = "connected"; | |
| 57 | + locationObject.insert(CONNECTED_KEY_IN_LOCATION, domainHandler.isConnected()); | |
| 58 | + | |
| 59 | + if (!addressManager->getRootPlaceID().isNull()) { | |
| 60 | + const QString PLACE_ID_KEY_IN_LOCATION = "place_id"; | |
| 61 | + locationObject.insert(PLACE_ID_KEY_IN_LOCATION, | |
| 62 | + uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID())); | |
| 63 | + } | |
| 64 | + | |
| 65 | + if (!domainHandler.getUUID().isNull()) { | |
| 66 | + const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id"; | |
| 67 | + locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION, | |
| 68 | + uuidStringWithoutCurlyBraces(domainHandler.getUUID())); | |
| 69 | + } | |
| 70 | + | |
| 71 | + // in case the place/domain isn't in the database, we send the network address and port | |
| 72 | + auto& domainSockAddr = domainHandler.getSockAddr(); | |
| 73 | + const QString NETWORK_ADRESS_KEY_IN_LOCATION = "network_address"; | |
| 74 | + locationObject.insert(NETWORK_ADRESS_KEY_IN_LOCATION, domainSockAddr.getAddress().toString()); | |
| 75 | + | |
| 76 | + const QString NETWORK_ADDRESS_PORT_IN_LOCATION = "network_port"; | |
| 77 | + locationObject.insert(NETWORK_ADDRESS_PORT_IN_LOCATION, domainSockAddr.getPort()); | |
| 78 | + | |
| 79 | + const QString FRIENDS_ONLY_KEY_IN_LOCATION = "friends_only"; | |
| 80 | + locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends)); | |
| 81 | + | |
| 82 | + // if we have a session ID add it now, otherwise add a null value | |
| 83 | + rootObject[SESSION_ID_KEY] = _sessionID.isEmpty() ? QJsonValue() : _sessionID; | |
| 84 | + | |
| 85 | + JSONCallbackParameters callbackParameters; | |
| 86 | + callbackParameters.jsonCallbackReceiver = this; | |
| 87 | + callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse"; | |
| 88 | + | |
| 89 | + // figure out if we'll send a fresh location or just a simple heartbeat | |
| 90 | + auto apiPath = API_USER_HEARTBEAT_PATH; | |
| 91 | + | |
| 92 | + if (locationObject != _lastLocationObject) { | |
| 93 | + // we have a changed location, send it now | |
| 94 | + _lastLocationObject = locationObject; | |
| 95 | + | |
| 96 | + rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject); | |
| 97 | + | |
| 98 | + apiPath = API_USER_LOCATION_PATH; | |
| 105 | 99 | } |
| 100 | + | |
| 101 | + accountManager.sendRequest(apiPath, AccountManagerAuth::Required, | |
| 102 | + QNetworkAccessManager::PutOperation, | |
| 103 | + callbackParameters, QJsonDocument(rootObject).toJson()); | |
| 104 | + | |
| 106 | 105 | } else if (UserActivityLogger::getInstance().isEnabled()) { |
| 107 | 106 | // we still send a heartbeat to the metaverse server for stats collection |
| 108 | 107 | |