Save.
This commit is contained in:
parent
fc28b3c6d2
commit
573c5c43fe
@ -76,10 +76,9 @@ void FeedDownloader::synchronizeAccountCaches(const QList<CacheForServiceRoot*>&
|
||||
}
|
||||
}
|
||||
|
||||
m_isCacheSynchronizationRunning = false;
|
||||
qDebugNN << LOGSEC_FEEDDOWNLOADER << "All caches synchronized.";
|
||||
emit cachesSynchronized();
|
||||
|
||||
m_isCacheSynchronizationRunning = false;
|
||||
}
|
||||
|
||||
void FeedDownloader::updateFeeds(const QList<Feed*>& feeds) {
|
||||
|
@ -34,6 +34,7 @@ FeedReader::FeedReader(QObject* parent)
|
||||
|
||||
connect(m_autoUpdateTimer, &QTimer::timeout, this, &FeedReader::executeNextAutoUpdate);
|
||||
updateAutoUpdateStatus();
|
||||
initializeFeedDownloader();
|
||||
|
||||
if (qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::FeedsUpdateOnStartup)).toBool()) {
|
||||
qDebugNN << LOGSEC_CORE
|
||||
@ -72,16 +73,12 @@ void FeedReader::updateFeeds(const QList<Feed*>& feeds) {
|
||||
return;
|
||||
}
|
||||
|
||||
initializeFeedDownloader();
|
||||
|
||||
QMetaObject::invokeMethod(m_feedDownloader, "updateFeeds",
|
||||
Qt::ConnectionType::QueuedConnection,
|
||||
Q_ARG(QList<Feed*>, feeds));
|
||||
}
|
||||
|
||||
void FeedReader::synchronizeMessageData(const QList<CacheForServiceRoot*>& caches) {
|
||||
initializeFeedDownloader();
|
||||
|
||||
QMetaObject::invokeMethod(m_feedDownloader, "synchronizeAccountCaches",
|
||||
Qt::ConnectionType::QueuedConnection,
|
||||
Q_ARG(QList<CacheForServiceRoot*>, caches));
|
||||
@ -91,8 +88,8 @@ void FeedReader::initializeFeedDownloader() {
|
||||
if (m_feedDownloader == nullptr) {
|
||||
qDebugNN << LOGSEC_CORE << "Creating FeedDownloader singleton.";
|
||||
|
||||
m_feedDownloaderThread = new QThread();
|
||||
m_feedDownloader = new FeedDownloader();
|
||||
m_feedDownloaderThread = new QThread();
|
||||
|
||||
// Downloader setup.
|
||||
qRegisterMetaType<QList<Feed*>>("QList<Feed*>");
|
||||
|
@ -216,7 +216,7 @@ void GmailServiceRoot::saveAllCachedData() {
|
||||
QStringList ids = i.value();
|
||||
|
||||
if (!ids.isEmpty()) {
|
||||
network()->markMessagesRead(key, ids, false);
|
||||
network()->markMessagesRead(key, ids);
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ void GmailServiceRoot::saveAllCachedData() {
|
||||
custom_ids.append(msg.m_customId);
|
||||
}
|
||||
|
||||
network()->markMessagesStarred(key, custom_ids, false);
|
||||
network()->markMessagesStarred(key, custom_ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ QList<Message> GmailNetworkFactory::messages(const QString& stream_id, Feed::Sta
|
||||
return messages;
|
||||
}
|
||||
|
||||
void GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async) {
|
||||
void GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids) {
|
||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||
|
||||
if (bearer.isEmpty()) {
|
||||
@ -252,28 +252,17 @@ void GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QS
|
||||
param_obj["ids"] = QJsonArray::fromStringList(custom_ids);
|
||||
|
||||
QJsonDocument param_doc(param_obj);
|
||||
QByteArray output;
|
||||
|
||||
// We send this batch.
|
||||
if (async) {
|
||||
NetworkFactory::performAsyncNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers);
|
||||
}
|
||||
else {
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers);
|
||||
}
|
||||
NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers);
|
||||
}
|
||||
|
||||
void GmailNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids, bool async) {
|
||||
void GmailNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids) {
|
||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||
|
||||
if (bearer.isEmpty()) {
|
||||
@ -305,25 +294,14 @@ void GmailNetworkFactory::markMessagesStarred(RootItem::Importance importance, c
|
||||
param_obj["ids"] = QJsonArray::fromStringList(custom_ids);
|
||||
|
||||
QJsonDocument param_doc(param_obj);
|
||||
QByteArray output;
|
||||
|
||||
// We send this batch.
|
||||
if (async) {
|
||||
NetworkFactory::performAsyncNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers);
|
||||
}
|
||||
else {
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers);
|
||||
}
|
||||
NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers);
|
||||
}
|
||||
|
||||
void GmailNetworkFactory::onTokensError(const QString& error, const QString& error_description) {
|
||||
|
@ -41,8 +41,8 @@ class GmailNetworkFactory : public QObject {
|
||||
Downloader* downloadAttachment(const QString& msg_id, const QString& attachment_id);
|
||||
|
||||
QList<Message> messages(const QString& stream_id, Feed::Status& error);
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async = true);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids, bool async = true);
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids);
|
||||
|
||||
private slots:
|
||||
void onTokensError(const QString& error, const QString& error_description);
|
||||
|
@ -159,7 +159,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
|
||||
QStringList ids = i.value();
|
||||
|
||||
if (!ids.isEmpty()) {
|
||||
network()->markMessagesRead(key, ids, false);
|
||||
network()->markMessagesRead(key, ids);
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
|
||||
custom_ids.append(msg.m_customId);
|
||||
}
|
||||
|
||||
network()->markMessagesStarred(key, custom_ids, false);
|
||||
network()->markMessagesStarred(key, custom_ids);
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
|
||||
QStringList messages = k.value();
|
||||
|
||||
if (!messages.isEmpty()) {
|
||||
network()->editLabels(label_custom_id, true, messages, false);
|
||||
network()->editLabels(label_custom_id, true, messages);
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
|
||||
QStringList messages = l.value();
|
||||
|
||||
if (!messages.isEmpty()) {
|
||||
network()->editLabels(label_custom_id, false, messages, false);
|
||||
network()->editLabels(label_custom_id, false, messages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ QList<Message> InoreaderNetworkFactory::messages(ServiceRoot* root, const QStrin
|
||||
}
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, const QStringList& msg_custom_ids, bool async) {
|
||||
void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, const QStringList& msg_custom_ids) {
|
||||
QString target_url = INOREADER_API_EDIT_TAG;
|
||||
|
||||
if (assign) {
|
||||
@ -219,11 +219,7 @@ void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, cons
|
||||
QRegularExpression regex_short_id(QSL("[0-9a-zA-Z]+$"));
|
||||
|
||||
for (const QString& id : msg_custom_ids) {
|
||||
QString simplified_id = regex_short_id.match(id).captured();
|
||||
auto numeric_id = simplified_id.toLongLong(nullptr, 16);
|
||||
QString decimal_id = QString::number(numeric_id);
|
||||
|
||||
trimmed_ids.append(QString("i=") + decimal_id);
|
||||
trimmed_ids.append(QString("i=") + id);
|
||||
}
|
||||
|
||||
QStringList working_subset; working_subset.reserve(std::min(200, trimmed_ids.size()));
|
||||
@ -231,7 +227,7 @@ void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, cons
|
||||
|
||||
// Now, we perform messages update in batches (max 200 messages per batch).
|
||||
while (!trimmed_ids.isEmpty()) {
|
||||
// We take 200 IDs.
|
||||
// We take 50 IDs.
|
||||
for (int i = 0; i < 50 && !trimmed_ids.isEmpty(); i++) {
|
||||
working_subset.append(trimmed_ids.takeFirst());
|
||||
}
|
||||
@ -239,35 +235,26 @@ void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, cons
|
||||
QString batch_final_url = target_url + working_subset.join(QL1C('&'));
|
||||
|
||||
// We send this batch.
|
||||
if (async) {
|
||||
NetworkFactory::performAsyncNetworkOperation(batch_final_url,
|
||||
timeout,
|
||||
QByteArray(),
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
headers);
|
||||
}
|
||||
else {
|
||||
QByteArray output;
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(batch_final_url,
|
||||
timeout,
|
||||
QByteArray(),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
headers);
|
||||
}
|
||||
NetworkFactory::performNetworkOperation(batch_final_url,
|
||||
timeout,
|
||||
QByteArray(),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
headers);
|
||||
|
||||
// Cleanup for next batch.
|
||||
working_subset.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids, bool async) {
|
||||
editLabels(INOREADER_FULL_STATE_READ, status == RootItem::ReadStatus::Read, msg_custom_ids, async);
|
||||
void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids) {
|
||||
editLabels(INOREADER_FULL_STATE_READ, status == RootItem::ReadStatus::Read, msg_custom_ids);
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids, bool async) {
|
||||
editLabels(INOREADER_FULL_STATE_IMPORTANT, importance == RootItem::Importance::Important, msg_custom_ids, async);
|
||||
void InoreaderNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids) {
|
||||
editLabels(INOREADER_FULL_STATE_IMPORTANT, importance == RootItem::Importance::Important, msg_custom_ids);
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::onTokensError(const QString& error, const QString& error_description) {
|
||||
|
@ -42,10 +42,10 @@ class InoreaderNetworkFactory : public QObject {
|
||||
|
||||
QList<Message> messages(ServiceRoot* root, const QString& stream_id, Feed::Status& error);
|
||||
|
||||
void editLabels(const QString& state, bool assign, const QStringList& msg_custom_ids, bool async = true);
|
||||
void editLabels(const QString& state, bool assign, const QStringList& msg_custom_ids);
|
||||
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids, bool async = true);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids, bool async = true);
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids);
|
||||
|
||||
private slots:
|
||||
void onTokensError(const QString& error, const QString& error_description);
|
||||
|
@ -312,7 +312,7 @@ QNetworkReply::NetworkError OwnCloudNetworkFactory::triggerFeedUpdate(int feed_i
|
||||
return (m_lastError = network_reply.first);
|
||||
}
|
||||
|
||||
void OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async) {
|
||||
void OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids) {
|
||||
QJsonObject json;
|
||||
QJsonArray ids;
|
||||
QString final_url;
|
||||
@ -335,30 +335,20 @@ void OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const
|
||||
headers << QPair<QByteArray, QByteArray>(HTTP_HEADERS_CONTENT_TYPE, OWNCLOUD_CONTENT_TYPE_JSON);
|
||||
headers << NetworkFactory::generateBasicAuthHeader(m_authUsername, m_authPassword);
|
||||
|
||||
if (async) {
|
||||
NetworkFactory::performAsyncNetworkOperation(final_url,
|
||||
qApp->settings()->value(GROUP(Feeds),
|
||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||
QJsonDocument(json).toJson(QJsonDocument::Compact),
|
||||
QNetworkAccessManager::PutOperation,
|
||||
headers);
|
||||
}
|
||||
else {
|
||||
QByteArray output;
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(final_url,
|
||||
qApp->settings()->value(GROUP(Feeds),
|
||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||
QJsonDocument(json).toJson(QJsonDocument::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::PutOperation,
|
||||
headers);
|
||||
}
|
||||
NetworkFactory::performNetworkOperation(final_url,
|
||||
qApp->settings()->value(GROUP(Feeds),
|
||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||
QJsonDocument(json).toJson(QJsonDocument::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::PutOperation,
|
||||
headers);
|
||||
}
|
||||
|
||||
void OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance,
|
||||
const QStringList& feed_ids,
|
||||
const QStringList& guid_hashes, bool async) {
|
||||
const QStringList& guid_hashes) {
|
||||
QJsonObject json;
|
||||
QJsonArray ids;
|
||||
QString final_url;
|
||||
@ -385,25 +375,15 @@ void OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance
|
||||
headers << QPair<QByteArray, QByteArray>(HTTP_HEADERS_CONTENT_TYPE, OWNCLOUD_CONTENT_TYPE_JSON);
|
||||
headers << NetworkFactory::generateBasicAuthHeader(m_authUsername, m_authPassword);
|
||||
|
||||
if (async) {
|
||||
NetworkFactory::performAsyncNetworkOperation(final_url,
|
||||
qApp->settings()->value(GROUP(Feeds),
|
||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||
QJsonDocument(json).toJson(QJsonDocument::Compact),
|
||||
QNetworkAccessManager::PutOperation,
|
||||
headers);
|
||||
}
|
||||
else {
|
||||
QByteArray output;
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(final_url,
|
||||
qApp->settings()->value(GROUP(Feeds),
|
||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||
QJsonDocument(json).toJson(QJsonDocument::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::PutOperation,
|
||||
headers);
|
||||
}
|
||||
NetworkFactory::performNetworkOperation(final_url,
|
||||
qApp->settings()->value(GROUP(Feeds),
|
||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||
QJsonDocument(json).toJson(QJsonDocument::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::PutOperation,
|
||||
headers);
|
||||
}
|
||||
|
||||
int OwnCloudNetworkFactory::batchSize() const {
|
||||
|
@ -96,9 +96,8 @@ class OwnCloudNetworkFactory {
|
||||
|
||||
// Misc methods.
|
||||
QNetworkReply::NetworkError triggerFeedUpdate(int feed_id);
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async = true);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& feed_ids,
|
||||
const QStringList& guid_hashes, bool async = true);
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& feed_ids, const QStringList& guid_hashes);
|
||||
|
||||
// Gets/sets the amount of messages to obtain during single feed update.
|
||||
int batchSize() const;
|
||||
|
@ -91,7 +91,7 @@ void OwnCloudServiceRoot::saveAllCachedData() {
|
||||
QStringList ids = i.value();
|
||||
|
||||
if (!ids.isEmpty()) {
|
||||
network()->markMessagesRead(key, ids, false);
|
||||
network()->markMessagesRead(key, ids);
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ void OwnCloudServiceRoot::saveAllCachedData() {
|
||||
guid_hashes.append(msg.m_customHash);
|
||||
}
|
||||
|
||||
network()->markMessagesStarred(key, feed_ids, guid_hashes, false);
|
||||
network()->markMessagesStarred(key, feed_ids, guid_hashes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -332,10 +332,7 @@ TtRssResponse TtRssNetworkFactory::setArticleLabel(const QStringList& article_id
|
||||
|
||||
TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList& ids,
|
||||
UpdateArticle::OperatingField field,
|
||||
UpdateArticle::Mode mode,
|
||||
bool async) {
|
||||
Q_UNUSED(async)
|
||||
|
||||
UpdateArticle::Mode mode) {
|
||||
QJsonObject json;
|
||||
|
||||
json["op"] = QSL("updateArticle");
|
||||
|
@ -161,8 +161,9 @@ class TtRssNetworkFactory {
|
||||
|
||||
TtRssResponse setArticleLabel(const QStringList& article_ids, const QString& label_custom_id, bool assign);
|
||||
|
||||
TtRssUpdateArticleResponse updateArticles(const QStringList& ids, UpdateArticle::OperatingField field,
|
||||
UpdateArticle::Mode mode, bool async = true);
|
||||
TtRssUpdateArticleResponse updateArticles(const QStringList& ids,
|
||||
UpdateArticle::OperatingField field,
|
||||
UpdateArticle::Mode mode);
|
||||
|
||||
TtRssSubscribeToFeedResponse subscribeToFeed(const QString& url, int category_id, bool protectd = false,
|
||||
const QString& username = QString(), const QString& password = QString());
|
||||
|
@ -132,8 +132,7 @@ void TtRssServiceRoot::saveAllCachedData() {
|
||||
UpdateArticle::OperatingField::Unread,
|
||||
key == RootItem::ReadStatus::Unread
|
||||
? UpdateArticle::Mode::SetToTrue
|
||||
: UpdateArticle::Mode::SetToFalse,
|
||||
false);
|
||||
: UpdateArticle::Mode::SetToFalse);
|
||||
|
||||
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) {
|
||||
addMessageStatesToCache(ids, key);
|
||||
@ -155,8 +154,7 @@ void TtRssServiceRoot::saveAllCachedData() {
|
||||
UpdateArticle::OperatingField::Starred,
|
||||
key == RootItem::Importance::Important
|
||||
? UpdateArticle::Mode::SetToTrue
|
||||
: UpdateArticle::Mode::SetToFalse,
|
||||
false);
|
||||
: UpdateArticle::Mode::SetToFalse);
|
||||
|
||||
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) {
|
||||
addMessageStatesToCache(messages, key);
|
||||
|
Loading…
x
Reference in New Issue
Block a user