From 2a36425b949fe6e578d880eb0e9476affe204caf Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 1 Jan 2021 20:34:15 +0100 Subject: [PATCH] Sync changes in messages when marked more than 1000 messages read/unread/starred in gmail. Also make sure that all messages states are synced when marking whole account read/unread. --- .../desktop/com.github.rssguard.appdata.xml | 2 +- resources/docs/Documentation.md | 2 +- .../miscellaneous/databasequeries.cpp | 2 +- .../gmail/network/gmailnetworkfactory.cpp | 64 ++++++++++++------- .../gmail/network/gmailnetworkfactory.h | 2 +- 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index 04871b89f..5dc6357a4 100644 --- a/resources/desktop/com.github.rssguard.appdata.xml +++ b/resources/desktop/com.github.rssguard.appdata.xml @@ -30,7 +30,7 @@ https://martinrotter.github.io/donate/ - + none diff --git a/resources/docs/Documentation.md b/resources/docs/Documentation.md index 8421b0215..34dfd4fe8 100644 --- a/resources/docs/Documentation.md +++ b/resources/docs/Documentation.md @@ -75,7 +75,7 @@ RSS Guard is simple (yet powerful) feed reader. It is able to fetch the most kno * Windows Vista and newer, * GNU/Linux, * Mac OS X, -* Android (buildable and running). +* Android (prebuilt binaries N/A at this point). ## List of main features * **support for online feed synchronization via plugins**, diff --git a/src/librssguard/miscellaneous/databasequeries.cpp b/src/librssguard/miscellaneous/databasequeries.cpp index 15a9c99a5..794d24cb0 100755 --- a/src/librssguard/miscellaneous/databasequeries.cpp +++ b/src/librssguard/miscellaneous/databasequeries.cpp @@ -1539,7 +1539,7 @@ QStringList DatabaseQueries::customIdsOfMessagesFromAccount(const QSqlDatabase& QStringList ids; q.setForwardOnly(true); - q.prepare(QSL("SELECT custom_id FROM Messages WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id;")); + q.prepare(QSL("SELECT custom_id FROM Messages WHERE is_pdeleted = 0 AND account_id = :account_id;")); q.bindValue(QSL(":account_id"), account_id); if (ok != nullptr) { diff --git a/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp b/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp index f755e68ea..cb2531a8f 100644 --- a/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp +++ b/src/librssguard/services/gmail/network/gmailnetworkfactory.cpp @@ -220,8 +220,7 @@ QList GmailNetworkFactory::messages(const QString& stream_id, Feed::Sta return messages; } -QNetworkReply::NetworkError GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status, - const QStringList& custom_ids) { +QNetworkReply::NetworkError GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status, QStringList custom_ids) { QString bearer = m_oauth2->bearer().toLocal8Bit(); if (bearer.isEmpty()) { @@ -250,21 +249,31 @@ QNetworkReply::NetworkError GmailNetworkFactory::markMessagesRead(RootItem::Read param_obj["addLabelIds"] = param_add; param_obj["removeLabelIds"] = param_remove; - param_obj["ids"] = QJsonArray::fromStringList(custom_ids); - QJsonDocument param_doc(param_obj); - QByteArray output; + // We need to operate withing allowed batches. + for (int i = 0; i < custom_ids.size(); i += GMAIL_MAX_BATCH_SIZE) { + auto batch = custom_ids.mid(i, GMAIL_MAX_BATCH_SIZE); - return NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS, - timeout, - param_doc.toJson(QJsonDocument::JsonFormat::Compact), - output, - QNetworkAccessManager::Operation::PostOperation, - headers).first; + param_obj["ids"] = QJsonArray::fromStringList(batch); + + QJsonDocument param_doc(param_obj); + QByteArray output; + auto result = NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS, + timeout, + param_doc.toJson(QJsonDocument::JsonFormat::Compact), + output, + QNetworkAccessManager::Operation::PostOperation, + headers).first; + + if (result != QNetworkReply::NetworkError::NoError) { + return result; + } + } + + return QNetworkReply::NetworkError::NoError; } -QNetworkReply::NetworkError GmailNetworkFactory::markMessagesStarred(RootItem::Importance importance, - const QStringList& custom_ids) { +QNetworkReply::NetworkError GmailNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids) { QString bearer = m_oauth2->bearer().toLocal8Bit(); if (bearer.isEmpty()) { @@ -293,17 +302,28 @@ QNetworkReply::NetworkError GmailNetworkFactory::markMessagesStarred(RootItem::I param_obj["addLabelIds"] = param_add; param_obj["removeLabelIds"] = param_remove; - param_obj["ids"] = QJsonArray::fromStringList(custom_ids); - QJsonDocument param_doc(param_obj); - QByteArray output; + // We need to operate withing allowed batches. + for (int i = 0; i < custom_ids.size(); i += GMAIL_MAX_BATCH_SIZE) { + auto batch = custom_ids.mid(i, GMAIL_MAX_BATCH_SIZE); - return NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS, - timeout, - param_doc.toJson(QJsonDocument::JsonFormat::Compact), - output, - QNetworkAccessManager::Operation::PostOperation, - headers).first; + param_obj["ids"] = QJsonArray::fromStringList(batch); + + QJsonDocument param_doc(param_obj); + QByteArray output; + auto result = NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS, + timeout, + param_doc.toJson(QJsonDocument::JsonFormat::Compact), + output, + QNetworkAccessManager::Operation::PostOperation, + headers).first; + + if (result != QNetworkReply::NetworkError::NoError) { + return result; + } + } + + return QNetworkReply::NetworkError::NoError; } void GmailNetworkFactory::onTokensError(const QString& error, const QString& error_description) { diff --git a/src/librssguard/services/gmail/network/gmailnetworkfactory.h b/src/librssguard/services/gmail/network/gmailnetworkfactory.h index b9ef44028..a43bf5ea2 100644 --- a/src/librssguard/services/gmail/network/gmailnetworkfactory.h +++ b/src/librssguard/services/gmail/network/gmailnetworkfactory.h @@ -41,7 +41,7 @@ class GmailNetworkFactory : public QObject { Downloader* downloadAttachment(const QString& msg_id, const QString& attachment_id); QList messages(const QString& stream_id, Feed::Status& error); - QNetworkReply::NetworkError markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids); + QNetworkReply::NetworkError markMessagesRead(RootItem::ReadStatus status, QStringList custom_ids); QNetworkReply::NetworkError markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids); private slots: