diff --git a/src/miscellaneous/databasequeries.cpp b/src/miscellaneous/databasequeries.cpp index 5dd826df4..5e0f8d8a4 100755 --- a/src/miscellaneous/databasequeries.cpp +++ b/src/miscellaneous/databasequeries.cpp @@ -1522,7 +1522,8 @@ Assignment DatabaseQueries::getInoreaderFeeds(QSqlDatabase db, int account_id, b return feeds; } -bool DatabaseQueries::storeNewInoreaderTokens(QSqlDatabase db, const QString& access_token, const QString& refresh_token, int account_id) { +bool DatabaseQueries::storeNewInoreaderTokens(QSqlDatabase db, const QString& access_token, + const QString& refresh_token, int account_id) { QSqlQuery query(db); query.prepare("UPDATE InoreaderAccounts " diff --git a/src/services/inoreader/inoreaderserviceroot.cpp b/src/services/inoreader/inoreaderserviceroot.cpp index 9b0dbad89..1030b316b 100755 --- a/src/services/inoreader/inoreaderserviceroot.cpp +++ b/src/services/inoreader/inoreaderserviceroot.cpp @@ -38,6 +38,7 @@ InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, Roo m_network->setParent(this); } + m_network->setService(this); setIcon(InoreaderEntryPoint().icon()); } diff --git a/src/services/inoreader/network/inoreadernetworkfactory.cpp b/src/services/inoreader/network/inoreadernetworkfactory.cpp index 3c71b458f..22a688171 100755 --- a/src/services/inoreader/network/inoreadernetworkfactory.cpp +++ b/src/services/inoreader/network/inoreadernetworkfactory.cpp @@ -22,6 +22,7 @@ #include "gui/dialogs/formmain.h" #include "gui/tabwidget.h" #include "miscellaneous/application.h" +#include "miscellaneous/databasequeries.h" #include "network-web/networkfactory.h" #include "network-web/oauth2service.h" #include "network-web/silentnetworkaccessmanager.h" @@ -29,6 +30,7 @@ #include "services/abstract/category.h" #include "services/inoreader/definitions.h" #include "services/inoreader/inoreaderfeed.h" +#include "services/inoreader/inoreaderserviceroot.h" #include #include @@ -36,12 +38,16 @@ #include InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(parent), - m_username(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE), + m_service(nullptr), m_username(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE), m_oauth2(new OAuth2Service(INOREADER_OAUTH_AUTH_URL, INOREADER_OAUTH_TOKEN_URL, INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, INOREADER_OAUTH_SCOPE)) { initializeOauth(); } +void InoreaderNetworkFactory::setService(InoreaderServiceRoot* service) { + m_service = service; +} + OAuth2Service* InoreaderNetworkFactory::oauth() const { return m_oauth2; } @@ -64,6 +70,14 @@ void InoreaderNetworkFactory::initializeOauth() { qApp->showGuiMessage("Authentication error - Inoreader", error_description, QSystemTrayIcon::Critical); }); + connect(m_oauth2, &OAuth2Service::tokensReceived, [this](QString access_token, QString refresh_token, int expires_in) { + Q_UNUSED(expires_in) + + if (m_service != nullptr && !access_token.isEmpty() && !refresh_token.isEmpty()) { + QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings); + DatabaseQueries::storeNewInoreaderTokens(database, access_token, refresh_token, m_service->accountId()); + } + }); } void InoreaderNetworkFactory::setUsername(const QString& username) { diff --git a/src/services/inoreader/network/inoreadernetworkfactory.h b/src/services/inoreader/network/inoreadernetworkfactory.h index b05503d82..929a23a09 100755 --- a/src/services/inoreader/network/inoreadernetworkfactory.h +++ b/src/services/inoreader/network/inoreadernetworkfactory.h @@ -26,6 +26,7 @@ #include class RootItem; +class InoreaderServiceRoot; class OAuth2Service; class InoreaderNetworkFactory : public QObject { @@ -34,6 +35,8 @@ class InoreaderNetworkFactory : public QObject { public: explicit InoreaderNetworkFactory(QObject* parent = nullptr); + void setService(InoreaderServiceRoot* service); + OAuth2Service* oauth() const; QString userName() const; @@ -57,6 +60,7 @@ class InoreaderNetworkFactory : public QObject { void initializeOauth(); private: + InoreaderServiceRoot* m_service; QString m_username; int m_batchSize; OAuth2Service* m_oauth2;