Save account cache before account is edited.

This commit is contained in:
Martin Rotter 2021-01-11 11:23:09 +01:00
parent 25329b61fa
commit c1fe781b50
13 changed files with 37 additions and 25 deletions

View File

@ -44,7 +44,7 @@ void FeedDownloader::updateAvailableFeeds() {
qDebugNN << LOGSEC_FEEDDOWNLOADER
<< "Saving cache for feed with DB ID '" << feed->id()
<< "' and title '" << feed->title() << "'.";
cache->saveAllCachedData();
cache->saveAllCachedData(false);
}
if (m_stopCacheSynchronization) {
@ -66,7 +66,7 @@ void FeedDownloader::synchronizeAccountCaches(const QList<CacheForServiceRoot*>&
for (CacheForServiceRoot* cache : caches) {
qDebugNN << LOGSEC_FEEDDOWNLOADER
<< "Synchronizing cache back to server on thread" << QUOTE_W_SPACE_DOT(QThread::currentThreadId());
cache->saveAllCachedData();
cache->saveAllCachedData(false);
if (m_stopCacheSynchronization) {
qWarningNN << LOGSEC_FEEDDOWNLOADER << "Aborting cache synchronization.";

View File

@ -22,7 +22,7 @@ class CacheForServiceRoot {
public:
explicit CacheForServiceRoot();
virtual void saveAllCachedData() = 0;
virtual void saveAllCachedData(bool ignore_errors) = 0;
void addLabelsAssignmentsToCache(const QStringList& ids_of_messages, const QString& lbl_custom_id, bool assign);
void addLabelsAssignmentsToCache(const QList<Message>& ids_of_messages, Label* lbl, bool assign);

View File

@ -16,7 +16,17 @@ FormAccountDetails::FormAccountDetails(const QIcon& icon, QWidget* parent) : QDi
createConnections();
}
void FormAccountDetails::apply() {}
void FormAccountDetails::apply() {
if (m_account != nullptr) {
// Perform last-time operations before account is changed.
auto* cached_account = dynamic_cast<CacheForServiceRoot*>(m_account);
if (cached_account != nullptr) {
qWarningNN << LOGSEC_CORE << "Last-time account cache saving before account gets changed.";
cached_account->saveAllCachedData(true);
}
}
}
void FormAccountDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) {
m_ui.m_tabWidget->insertTab(index, custom_tab, title);

View File

@ -94,7 +94,7 @@ QList<QAction*> ServiceRoot::serviceMenu() {
auto* act_sync_cache = new QAction(qApp->icons()->fromTheme(QSL("view-refresh")), tr("Synchronize message cache"), this);
connect(act_sync_cache, &QAction::triggered, this, [cache]() {
cache->saveAllCachedData();
cache->saveAllCachedData(false);
});
m_serviceMenu.append(act_sync_cache);

View File

@ -205,7 +205,7 @@ QString GmailServiceRoot::additionalTooltip() const {
network()->oauth()->tokensExpireIn().toString() : QSL("-"));
}
void GmailServiceRoot::saveAllCachedData() {
void GmailServiceRoot::saveAllCachedData(bool ignore_errors) {
auto msg_cache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead);
@ -216,7 +216,7 @@ void GmailServiceRoot::saveAllCachedData() {
QStringList ids = i.value();
if (!ids.isEmpty()) {
if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError) {
if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addMessageStatesToCache(ids, key);
}
}
@ -237,7 +237,7 @@ void GmailServiceRoot::saveAllCachedData() {
custom_ids.append(msg.m_customId);
}
if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError) {
if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addMessageStatesToCache(messages, key);
}
}

View File

@ -33,7 +33,7 @@ class GmailServiceRoot : public ServiceRoot, public CacheForServiceRoot {
virtual void start(bool freshly_activated);
virtual QString code() const;
virtual QString additionalTooltip() const;
virtual void saveAllCachedData();
virtual void saveAllCachedData(bool ignore_errors);
void updateTitle();

View File

@ -148,7 +148,7 @@ RootItem* InoreaderServiceRoot::obtainNewTreeForSyncIn() const {
}
}
void InoreaderServiceRoot::saveAllCachedData() {
void InoreaderServiceRoot::saveAllCachedData(bool ignore_errors) {
auto msg_cache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead);
@ -159,7 +159,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
QStringList ids = i.value();
if (!ids.isEmpty()) {
if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError) {
if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addMessageStatesToCache(ids, key);
}
}
@ -180,7 +180,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
custom_ids.append(msg.m_customId);
}
if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError) {
if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addMessageStatesToCache(messages, key);
}
}
@ -195,7 +195,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
QStringList messages = k.value();
if (!messages.isEmpty()) {
if (network()->editLabels(label_custom_id, true, messages) != QNetworkReply::NetworkError::NoError) {
if (network()->editLabels(label_custom_id, true, messages) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addLabelsAssignmentsToCache(messages, label_custom_id, true);
}
}
@ -210,7 +210,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
QStringList messages = l.value();
if (!messages.isEmpty()) {
if (network()->editLabels(label_custom_id, false, messages) != QNetworkReply::NetworkError::NoError) {
if (network()->editLabels(label_custom_id, false, messages) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addLabelsAssignmentsToCache(messages, label_custom_id, false);
}
}

View File

@ -31,7 +31,7 @@ class InoreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot {
virtual void start(bool freshly_activated);
virtual QString code() const;
virtual QString additionalTooltip() const;
virtual void saveAllCachedData();
virtual void saveAllCachedData(bool ignore_errors);
void updateTitle();

View File

@ -80,7 +80,7 @@ OwnCloudNetworkFactory* OwnCloudServiceRoot::network() const {
return m_network;
}
void OwnCloudServiceRoot::saveAllCachedData() {
void OwnCloudServiceRoot::saveAllCachedData(bool ignore_errors) {
auto msg_cache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead);
@ -93,7 +93,7 @@ void OwnCloudServiceRoot::saveAllCachedData() {
if (!ids.isEmpty()) {
auto res = network()->markMessagesRead(key, ids);
if (res.first != QNetworkReply::NetworkError::NoError) {
if (!ignore_errors && res.first != QNetworkReply::NetworkError::NoError) {
addMessageStatesToCache(ids, key);
}
}
@ -117,7 +117,7 @@ void OwnCloudServiceRoot::saveAllCachedData() {
auto res = network()->markMessagesStarred(key, feed_ids, guid_hashes);
if (res.first != QNetworkReply::NetworkError::NoError) {
if (!ignore_errors && res.first != QNetworkReply::NetworkError::NoError) {
addMessageStatesToCache(messages, key);
}
}

View File

@ -27,7 +27,7 @@ class OwnCloudServiceRoot : public ServiceRoot, public CacheForServiceRoot {
virtual bool supportsCategoryAdding() const;
virtual void start(bool freshly_activated);
virtual QString code() const;
virtual void saveAllCachedData();
virtual void saveAllCachedData(bool ignore_errors);
OwnCloudNetworkFactory* network() const;

View File

@ -28,6 +28,8 @@ TtRssServiceRoot* FormEditTtRssAccount::addEditAccount(TtRssServiceRoot* account
}
void FormEditTtRssAccount::apply() {
FormAccountDetails::apply();
bool editing_account = true;
if (m_account == nullptr) {

View File

@ -117,7 +117,7 @@ bool TtRssServiceRoot::canBeDeleted() const {
return true;
}
void TtRssServiceRoot::saveAllCachedData() {
void TtRssServiceRoot::saveAllCachedData(bool ignore_errors) {
auto msg_cache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead);
@ -134,7 +134,7 @@ void TtRssServiceRoot::saveAllCachedData() {
? UpdateArticle::Mode::SetToTrue
: UpdateArticle::Mode::SetToFalse);
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) {
if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) {
addMessageStatesToCache(ids, key);
}
}
@ -156,7 +156,7 @@ void TtRssServiceRoot::saveAllCachedData() {
? UpdateArticle::Mode::SetToTrue
: UpdateArticle::Mode::SetToFalse);
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) {
if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) {
addMessageStatesToCache(messages, key);
}
}
@ -173,7 +173,7 @@ void TtRssServiceRoot::saveAllCachedData() {
if (!messages.isEmpty()) {
auto res = network()->setArticleLabel(messages, label_custom_id, true);
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) {
if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) {
addLabelsAssignmentsToCache(messages, label_custom_id, true);
}
}
@ -190,7 +190,7 @@ void TtRssServiceRoot::saveAllCachedData() {
if (!messages.isEmpty()) {
auto res = network()->setArticleLabel(messages, label_custom_id, false);
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) {
if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) {
addLabelsAssignmentsToCache(messages, label_custom_id, false);
}
}

View File

@ -32,7 +32,7 @@ class TtRssServiceRoot : public ServiceRoot, public CacheForServiceRoot {
virtual bool supportsCategoryAdding() const;
virtual void addNewFeed(RootItem* selected_item, const QString& url = QString());
virtual QString additionalTooltip() const;
virtual void saveAllCachedData();
virtual void saveAllCachedData(bool ignore_errors);
// Access to network.
TtRssNetworkFactory* network() const;