mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-13 11:37:47 +02:00
Move session id storage to AccountManager
This commit is contained in:
parent
f2bedc546f
commit
ed88232fb0
4 changed files with 13 additions and 12 deletions
|
@ -80,7 +80,8 @@ void DiscoverabilityManager::updateLocation() {
|
|||
locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends));
|
||||
|
||||
// if we have a session ID add it now, otherwise add a null value
|
||||
rootObject[SESSION_ID_KEY] = _sessionID.isEmpty() ? QJsonValue() : _sessionID;
|
||||
auto sessionID = accountManager->getSessionID();
|
||||
rootObject[SESSION_ID_KEY] = sessionID.isNull() ? QJsonValue() : sessionID.toString();
|
||||
|
||||
JSONCallbackParameters callbackParameters;
|
||||
callbackParameters.jsonCallbackReceiver = this;
|
||||
|
@ -110,11 +111,8 @@ void DiscoverabilityManager::updateLocation() {
|
|||
callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse";
|
||||
|
||||
QJsonObject heartbeatObject;
|
||||
if (!_sessionID.isEmpty()) {
|
||||
heartbeatObject[SESSION_ID_KEY] = _sessionID;
|
||||
} else {
|
||||
heartbeatObject[SESSION_ID_KEY] = QJsonValue();
|
||||
}
|
||||
auto sessionID = accountManager->getSessionID();
|
||||
heartbeatObject[SESSION_ID_KEY] = sessionID.isNull() ? QJsonValue() : sessionID.toString();
|
||||
|
||||
accountManager->sendRequest(API_USER_HEARTBEAT_PATH, AccountManagerAuth::Optional,
|
||||
QNetworkAccessManager::PutOperation, callbackParameters,
|
||||
|
@ -126,11 +124,11 @@ void DiscoverabilityManager::handleHeartbeatResponse(QNetworkReply& requestReply
|
|||
auto dataObject = AccountManager::dataObjectFromResponse(requestReply);
|
||||
|
||||
if (!dataObject.isEmpty()) {
|
||||
_sessionID = dataObject[SESSION_ID_KEY].toString();
|
||||
auto sessionID = dataObject[SESSION_ID_KEY].toString();
|
||||
|
||||
// give that session ID to the account manager
|
||||
auto accountManager = DependencyManager::get<AccountManager>();
|
||||
accountManager->setSessionID(_sessionID);
|
||||
accountManager->setSessionID(sessionID);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ private:
|
|||
DiscoverabilityManager();
|
||||
|
||||
Setting::Handle<int> _mode;
|
||||
QString _sessionID;
|
||||
QJsonObject _lastLocationObject;
|
||||
};
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ Q_DECLARE_METATYPE(QNetworkAccessManager::Operation)
|
|||
Q_DECLARE_METATYPE(JSONCallbackParameters)
|
||||
|
||||
const QString ACCOUNTS_GROUP = "accounts";
|
||||
static const auto METAVERSE_SESSION_ID_HEADER = QString("HFM-SessionID").toLocal8Bit();
|
||||
|
||||
JSONCallbackParameters::JSONCallbackParameters(QObject* jsonCallbackReceiver, const QString& jsonCallbackMethod,
|
||||
QObject* errorCallbackReceiver, const QString& errorCallbackMethod,
|
||||
|
@ -221,8 +222,7 @@ void AccountManager::sendRequest(const QString& path,
|
|||
// if we're allowed to send usage data, include whatever the current session ID is with this request
|
||||
auto& activityLogger = UserActivityLogger::getInstance();
|
||||
if (activityLogger.isEnabled()) {
|
||||
static const QString METAVERSE_SESSION_ID_HEADER = "HFM-SessionID";
|
||||
networkRequest.setRawHeader(METAVERSE_SESSION_ID_HEADER.toLocal8Bit(),
|
||||
networkRequest.setRawHeader(METAVERSE_SESSION_ID_HEADER,
|
||||
uuidStringWithoutCurlyBraces(_sessionID).toLocal8Bit());
|
||||
}
|
||||
|
||||
|
@ -321,6 +321,9 @@ void AccountManager::processReply() {
|
|||
QNetworkReply* requestReply = reinterpret_cast<QNetworkReply*>(sender());
|
||||
|
||||
if (requestReply->error() == QNetworkReply::NoError) {
|
||||
if (requestReply->hasRawHeader(METAVERSE_SESSION_ID_HEADER)) {
|
||||
_sessionID = requestReply->rawHeader(METAVERSE_SESSION_ID_HEADER);
|
||||
}
|
||||
passSuccessToCallback(requestReply);
|
||||
} else {
|
||||
passErrorToCallback(requestReply);
|
||||
|
|
|
@ -86,6 +86,7 @@ public:
|
|||
|
||||
static QJsonObject dataObjectFromResponse(QNetworkReply& requestReply);
|
||||
|
||||
QUuid getSessionID() const { return _sessionID; }
|
||||
void setSessionID(const QUuid& sessionID) { _sessionID = sessionID; }
|
||||
|
||||
public slots:
|
||||
|
@ -139,7 +140,7 @@ private:
|
|||
bool _isWaitingForKeypairResponse { false };
|
||||
QByteArray _pendingPrivateKey;
|
||||
|
||||
QUuid _sessionID;
|
||||
QUuid _sessionID { QUuid::createUuid() };
|
||||
};
|
||||
|
||||
#endif // hifi_AccountManager_h
|
||||
|
|
Loading…
Reference in a new issue