Fix connection issue syncing two AccountManagers

This commit is contained in:
Gabriel Calero 2018-05-03 17:53:18 -03:00
parent ec838b1417
commit a767540b76
3 changed files with 29 additions and 2 deletions

View file

@ -22,9 +22,21 @@ AndroidHelper::~AndroidHelper() {
}
void AndroidHelper::init() {
qDebug() << "[LOGIN] AndroidHelper::init";
workerThread.start();
_accountManager = DependencyManager::get<AccountManager>();
_accountManager = QSharedPointer<AccountManager>(new AccountManager, &QObject::deleteLater);
_accountManager->setIsAgent(true);
_accountManager->setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL());
_accountManager->setSessionID(DependencyManager::get<AccountManager>()->getSessionID());
connect(_accountManager.data(), &AccountManager::loginComplete, [](const QUrl& authURL) {
DependencyManager::get<AccountManager>()->setAccountInfo(AndroidHelper::instance().getAccountManager()->getAccountInfo());
DependencyManager::get<AccountManager>()->setAuthURL(authURL);
});
connect(_accountManager.data(), &AccountManager::logoutComplete, [] () {
DependencyManager::get<AccountManager>()->logout();
});
_accountManager->moveToThread(&workerThread);
}

View file

@ -453,6 +453,20 @@ void AccountManager::removeAccountFromFile() {
<< "from settings file.";
}
void AccountManager::setAccountInfo(const DataServerAccountInfo &newAccountInfo) {
_accountInfo = newAccountInfo;
_pendingPrivateKey.clear();
if (_isAgent && !_accountInfo.getAccessToken().token.isEmpty() && !_accountInfo.hasProfile()) {
// we are missing profile information, request it now
requestProfile();
}
// prepare to refresh our token if it is about to expire
if (needsToRefreshToken()) {
refreshAccessToken();
}
}
bool AccountManager::hasValidAccessToken() {
if (_accountInfo.getAccessToken().token.isEmpty() || _accountInfo.getAccessToken().isExpired()) {

View file

@ -88,6 +88,7 @@ public:
void requestProfile();
DataServerAccountInfo& getAccountInfo() { return _accountInfo; }
void setAccountInfo(const DataServerAccountInfo &newAccountInfo);
static QJsonObject dataObjectFromResponse(QNetworkReply& requestReply);