almost done problem with synchronizing cached msg changes
This commit is contained in:
parent
ff04afd46b
commit
da08ce8206
@ -216,7 +216,9 @@ void GmailServiceRoot::saveAllCachedData() {
|
||||
QStringList ids = i.value();
|
||||
|
||||
if (!ids.isEmpty()) {
|
||||
network()->markMessagesRead(key, ids);
|
||||
if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError) {
|
||||
addMessageStatesToCache(ids, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +237,9 @@ void GmailServiceRoot::saveAllCachedData() {
|
||||
custom_ids.append(msg.m_customId);
|
||||
}
|
||||
|
||||
network()->markMessagesStarred(key, custom_ids);
|
||||
if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError) {
|
||||
addMessageStatesToCache(messages, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,11 +220,12 @@ QList<Message> GmailNetworkFactory::messages(const QString& stream_id, Feed::Sta
|
||||
return messages;
|
||||
}
|
||||
|
||||
void GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids) {
|
||||
QNetworkReply::NetworkError GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status,
|
||||
const QStringList& custom_ids) {
|
||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||
|
||||
if (bearer.isEmpty()) {
|
||||
return;
|
||||
return QNetworkReply::NetworkError::AuthenticationRequiredError;
|
||||
}
|
||||
|
||||
QList<QPair<QByteArray, QByteArray>> headers;
|
||||
@ -254,19 +255,20 @@ void GmailNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QS
|
||||
QJsonDocument param_doc(param_obj);
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers);
|
||||
return NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers).first;
|
||||
}
|
||||
|
||||
void 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()) {
|
||||
return;
|
||||
return QNetworkReply::NetworkError::AuthenticationRequiredError;
|
||||
}
|
||||
|
||||
QList<QPair<QByteArray, QByteArray>> headers;
|
||||
@ -296,12 +298,12 @@ void GmailNetworkFactory::markMessagesStarred(RootItem::Importance importance, c
|
||||
QJsonDocument param_doc(param_obj);
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers);
|
||||
return NetworkFactory::performNetworkOperation(GMAIL_API_BATCH_UPD_LABELS,
|
||||
timeout,
|
||||
param_doc.toJson(QJsonDocument::JsonFormat::Compact),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers).first;
|
||||
}
|
||||
|
||||
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);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids);
|
||||
QNetworkReply::NetworkError markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids);
|
||||
QNetworkReply::NetworkError markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids);
|
||||
|
||||
private slots:
|
||||
void onTokensError(const QString& error, const QString& error_description);
|
||||
|
@ -159,7 +159,9 @@ void InoreaderServiceRoot::saveAllCachedData() {
|
||||
QStringList ids = i.value();
|
||||
|
||||
if (!ids.isEmpty()) {
|
||||
network()->markMessagesRead(key, ids);
|
||||
if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError) {
|
||||
addMessageStatesToCache(ids, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -178,7 +180,9 @@ void InoreaderServiceRoot::saveAllCachedData() {
|
||||
custom_ids.append(msg.m_customId);
|
||||
}
|
||||
|
||||
network()->markMessagesStarred(key, custom_ids);
|
||||
if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError) {
|
||||
addMessageStatesToCache(messages, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,7 +195,9 @@ void InoreaderServiceRoot::saveAllCachedData() {
|
||||
QStringList messages = k.value();
|
||||
|
||||
if (!messages.isEmpty()) {
|
||||
network()->editLabels(label_custom_id, true, messages);
|
||||
if (network()->editLabels(label_custom_id, true, messages) != QNetworkReply::NetworkError::NoError) {
|
||||
addLabelsAssignmentsToCache(messages, label_custom_id, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +210,9 @@ void InoreaderServiceRoot::saveAllCachedData() {
|
||||
QStringList messages = l.value();
|
||||
|
||||
if (!messages.isEmpty()) {
|
||||
network()->editLabels(label_custom_id, false, messages);
|
||||
if (network()->editLabels(label_custom_id, false, messages) != QNetworkReply::NetworkError::NoError) {
|
||||
addLabelsAssignmentsToCache(messages, label_custom_id, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +194,8 @@ QList<Message> InoreaderNetworkFactory::messages(ServiceRoot* root, const QStrin
|
||||
}
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, const QStringList& msg_custom_ids) {
|
||||
QNetworkReply::NetworkError InoreaderNetworkFactory::editLabels(const QString& state, bool assign,
|
||||
const QStringList& msg_custom_ids) {
|
||||
QString target_url = INOREADER_API_EDIT_TAG;
|
||||
|
||||
if (assign) {
|
||||
@ -207,7 +208,7 @@ void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, cons
|
||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||
|
||||
if (bearer.isEmpty()) {
|
||||
return;
|
||||
return QNetworkReply::NetworkError::AuthenticationRequiredError;
|
||||
}
|
||||
|
||||
QList<QPair<QByteArray, QByteArray>> headers;
|
||||
@ -222,7 +223,7 @@ void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, cons
|
||||
trimmed_ids.append(QString("i=") + id);
|
||||
}
|
||||
|
||||
QStringList working_subset; working_subset.reserve(std::min(200, trimmed_ids.size()));
|
||||
QStringList working_subset; working_subset.reserve(std::min(50, trimmed_ids.size()));
|
||||
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||
|
||||
// Now, we perform messages update in batches (max 200 messages per batch).
|
||||
@ -236,25 +237,30 @@ void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, cons
|
||||
|
||||
// We send this batch.
|
||||
QByteArray output;
|
||||
auto result = NetworkFactory::performNetworkOperation(batch_final_url,
|
||||
timeout,
|
||||
QByteArray(),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
headers);
|
||||
|
||||
NetworkFactory::performNetworkOperation(batch_final_url,
|
||||
timeout,
|
||||
QByteArray(),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
headers);
|
||||
if (result.first != QNetworkReply::NetworkError::NoError) {
|
||||
return result.first;
|
||||
}
|
||||
|
||||
// Cleanup for next batch.
|
||||
working_subset.clear();
|
||||
}
|
||||
|
||||
return QNetworkReply::NetworkError::NoError;
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids) {
|
||||
editLabels(INOREADER_FULL_STATE_READ, status == RootItem::ReadStatus::Read, msg_custom_ids);
|
||||
QNetworkReply::NetworkError InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids) {
|
||||
return editLabels(INOREADER_FULL_STATE_READ, status == RootItem::ReadStatus::Read, msg_custom_ids);
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids) {
|
||||
editLabels(INOREADER_FULL_STATE_IMPORTANT, importance == RootItem::Importance::Important, msg_custom_ids);
|
||||
QNetworkReply::NetworkError InoreaderNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids) {
|
||||
return 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);
|
||||
QNetworkReply::NetworkError editLabels(const QString& state, bool assign, const QStringList& msg_custom_ids);
|
||||
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids);
|
||||
QNetworkReply::NetworkError markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids);
|
||||
QNetworkReply::NetworkError markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids);
|
||||
|
||||
private slots:
|
||||
void onTokensError(const QString& error, const QString& error_description);
|
||||
|
Loading…
x
Reference in New Issue
Block a user