From 7fa57bd6acd901092ab29794e5fef07273ad7fcc Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 1 Mar 2021 11:12:20 +0100 Subject: [PATCH] Different redirect URI ports for each service to avoid some problems, some simplifications of sync-in process. --- src/librssguard/definitions/definitions.h | 1 - .../miscellaneous/databasequeries.cpp | 6 ++++ .../services/abstract/serviceroot.cpp | 33 +++++++++++-------- .../services/abstract/serviceroot.h | 1 + src/librssguard/services/gmail/definitions.h | 7 ++-- .../gmail/network/gmailnetworkfactory.cpp | 2 +- .../services/inoreader/definitions.h | 9 ++--- .../network/inoreadernetworkfactory.cpp | 4 +-- 8 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index 1b8e879bb..81f787a5a 100755 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -23,7 +23,6 @@ #define ADBLOCK_EASYLIST_URL "https://easylist.to/easylist/easylist.txt" #define OAUTH_DECRYPTION_KEY 11451167756100761335ul -#define OAUTH_REDIRECT_URI_PORT 14488 #define OAUTH_REDIRECT_URI "http://localhost" #define ENCLOSURES_OUTER_SEPARATOR '#' diff --git a/src/librssguard/miscellaneous/databasequeries.cpp b/src/librssguard/miscellaneous/databasequeries.cpp index 85ed334f9..0cc612dac 100755 --- a/src/librssguard/miscellaneous/databasequeries.cpp +++ b/src/librssguard/miscellaneous/databasequeries.cpp @@ -2187,6 +2187,9 @@ bool DatabaseQueries::storeNewOauthTokens(const QSqlDatabase& db, query.bindValue(QSL(":id"), account_id); if (!query.exec() || !query.next()) { + qWarningNN << LOGSEC_OAUTH + << "Cannot fetch custom data column for storing of OAuth tokens, because of error:" + << QUOTE_W_SPACE_DOT(query.lastError().text()); return false; } @@ -2200,6 +2203,9 @@ bool DatabaseQueries::storeNewOauthTokens(const QSqlDatabase& db, query.bindValue(QSL(":id"), account_id); if (!query.exec()) { + qWarningNN << LOGSEC_OAUTH + << "Cannot store OAuth tokens, because of error:" + << QUOTE_W_SPACE_DOT(query.lastError().text()); return false; } else { diff --git a/src/librssguard/services/abstract/serviceroot.cpp b/src/librssguard/services/abstract/serviceroot.cpp index 506c67c52..f1901e2fd 100644 --- a/src/librssguard/services/abstract/serviceroot.cpp +++ b/src/librssguard/services/abstract/serviceroot.cpp @@ -21,6 +21,8 @@ ServiceRoot::ServiceRoot(RootItem* parent) m_labelsNode(new LabelsNode(this)), m_accountId(NO_PARENT_CATEGORY), m_networkProxy(QNetworkProxy()) { setKind(RootItem::Kind::ServiceRoot); setCreationDate(QDateTime::currentDateTime()); + + appendCommonNodes(); } ServiceRoot::~ServiceRoot() = default; @@ -206,6 +208,22 @@ void ServiceRoot::cleanAllItemsFromModel() { } } +void ServiceRoot::appendCommonNodes() { + if (recycleBin() != nullptr && !childItems().contains(recycleBin())) { + appendChild(recycleBin()); + } + + if (importantNode() != nullptr && !childItems().contains(importantNode())) { + appendChild(importantNode()); + } + + if (labelsNode() != nullptr) { + if (!childItems().contains(labelsNode())) { + appendChild(labelsNode()); + } + } +} + bool ServiceRoot::cleanFeeds(QList items, bool clean_read_only) { QSqlDatabase database = qApp->database()->connection(metaObject()->className()); @@ -408,26 +426,15 @@ void ServiceRoot::syncIn() { setIcon(original_icon); itemChanged(getSubTree()); - requestItemExpand({ this }, true); + requestItemExpand(getSubTree(), true); } void ServiceRoot::performInitialAssembly(const Assignment& categories, const Assignment& feeds, const QList& labels) { - // All data are now obtained, lets create the hierarchy. assembleCategories(categories); assembleFeeds(feeds); - - // As the last item, add recycle bin, which is needed. - appendChild(recycleBin()); - appendChild(importantNode()); - - if (labelsNode() != nullptr) { - appendChild(labelsNode()); - labelsNode()->loadLabels(labels); - requestItemExpand({ labelsNode() }, true); - } - + labelsNode()->loadLabels(labels); updateCounts(true); } diff --git a/src/librssguard/services/abstract/serviceroot.h b/src/librssguard/services/abstract/serviceroot.h index 711c82fad..7aabcd097 100644 --- a/src/librssguard/services/abstract/serviceroot.h +++ b/src/librssguard/services/abstract/serviceroot.h @@ -209,6 +209,7 @@ class ServiceRoot : public RootItem { void removeOldAccountFromDatabase(bool including_messages); void storeNewFeedTree(RootItem* root); void cleanAllItemsFromModel(); + void appendCommonNodes(); // Removes messages which do not belong to any // existing feed. diff --git a/src/librssguard/services/gmail/definitions.h b/src/librssguard/services/gmail/definitions.h index 0064c9444..aa6fbd8a9 100644 --- a/src/librssguard/services/gmail/definitions.h +++ b/src/librssguard/services/gmail/definitions.h @@ -3,9 +3,10 @@ #ifndef GMAIL_DEFINITIONS_H #define GMAIL_DEFINITIONS_H -#define GMAIL_OAUTH_AUTH_URL "https://accounts.google.com/o/oauth2/auth" -#define GMAIL_OAUTH_TOKEN_URL "https://accounts.google.com/o/oauth2/token" -#define GMAIL_OAUTH_SCOPE "https://mail.google.com/" +#define GMAIL_OAUTH_REDIRECT_URI_PORT 14499 +#define GMAIL_OAUTH_AUTH_URL "https://accounts.google.com/o/oauth2/auth" +#define GMAIL_OAUTH_TOKEN_URL "https://accounts.google.com/o/oauth2/token" +#define GMAIL_OAUTH_SCOPE "https://mail.google.com/" #define GMAIL_REG_API_URL "https://console.developers.google.com/apis/credentials" diff --git a/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp b/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp index ca949539a..1b42757e1 100644 --- a/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp +++ b/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp @@ -125,7 +125,7 @@ void GmailNetworkFactory::initializeOauth() { m_oauth2->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + - QString::number(OAUTH_REDIRECT_URI_PORT)); + QString::number(GMAIL_OAUTH_REDIRECT_URI_PORT)); connect(m_oauth2, &OAuth2Service::tokensRetrieveError, this, &GmailNetworkFactory::onTokensError); connect(m_oauth2, &OAuth2Service::authFailed, this, &GmailNetworkFactory::onAuthFailed); diff --git a/src/librssguard/services/inoreader/definitions.h b/src/librssguard/services/inoreader/definitions.h index 487cf9f14..83d81214a 100644 --- a/src/librssguard/services/inoreader/definitions.h +++ b/src/librssguard/services/inoreader/definitions.h @@ -3,10 +3,11 @@ #ifndef INOREADER_DEFINITIONS_H #define INOREADER_DEFINITIONS_H -#define INOREADER_OAUTH_SCOPE "read write" -#define INOREADER_OAUTH_TOKEN_URL "https://www.inoreader.com/oauth2/token" -#define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth" -#define INOREADER_REG_API_URL "https://www.inoreader.com/developers/register-app" +#define INOREADER_OAUTH_REDIRECT_URI_PORT 14488 +#define INOREADER_OAUTH_SCOPE "read write" +#define INOREADER_OAUTH_TOKEN_URL "https://www.inoreader.com/oauth2/token" +#define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth" +#define INOREADER_REG_API_URL "https://www.inoreader.com/developers/register-app" #define INOREADER_REFRESH_TOKEN_KEY "refresh_token" #define INOREADER_ACCESS_TOKEN_KEY "access_token" diff --git a/src/librssguard/services/inoreader/network/inoreadernetworkfactory.cpp b/src/librssguard/services/inoreader/network/inoreadernetworkfactory.cpp index 810002238..3db230524 100644 --- a/src/librssguard/services/inoreader/network/inoreadernetworkfactory.cpp +++ b/src/librssguard/services/inoreader/network/inoreadernetworkfactory.cpp @@ -60,7 +60,7 @@ void InoreaderNetworkFactory::initializeOauth() { m_oauth2->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + - QString::number(OAUTH_REDIRECT_URI_PORT)); + QString::number(INOREADER_OAUTH_REDIRECT_URI_PORT)); connect(m_oauth2, &OAuth2Service::tokensRetrieveError, this, &InoreaderNetworkFactory::onTokensError); connect(m_oauth2, &OAuth2Service::authFailed, this, &InoreaderNetworkFactory::onAuthFailed); @@ -68,7 +68,7 @@ void InoreaderNetworkFactory::initializeOauth() { Q_UNUSED(expires_in) Q_UNUSED(access_token) - if (m_service != nullptr && !refresh_token.isEmpty()) { + if (m_service != nullptr && m_service->accountId() > 0 && !refresh_token.isEmpty()) { QSqlDatabase database = qApp->database()->connection(metaObject()->className()); DatabaseQueries::storeNewOauthTokens(database, refresh_token, m_service->accountId());