From 1c0c5aed9248f6ea7e2f94737337e8c3d83766ee Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 1 Apr 2021 06:06:16 +0200 Subject: [PATCH] make sure unread feeditem is updated when deleting stuff --- .../desktop/com.github.rssguard.appdata.xml | 2 +- src/librssguard/core/feedsmodel.cpp | 5 ++++ src/librssguard/database/databasequeries.cpp | 28 +++++++------------ src/librssguard/database/databasequeries.h | 2 +- src/librssguard/services/abstract/feed.cpp | 9 +++--- .../services/standard/standardfeed.h | 19 +++++-------- 6 files changed, 28 insertions(+), 37 deletions(-) diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index 58f69a1b0..f6045e0cd 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/src/librssguard/core/feedsmodel.cpp b/src/librssguard/core/feedsmodel.cpp index 40edd88f4..becd66971 100644 --- a/src/librssguard/core/feedsmodel.cpp +++ b/src/librssguard/core/feedsmodel.cpp @@ -261,6 +261,11 @@ void FeedsModel::removeItem(RootItem* deleting_item) { beginRemoveRows(parent_index, index.row(), index.row()); parent_item->removeChild(deleting_item); endRemoveRows(); + + if (deleting_item->kind() != RootItem::Kind::ServiceRoot) { + deleting_item->getParentServiceRoot()->updateCounts(true); + } + deleting_item->deleteLater(); notifyWithCounts(); } diff --git a/src/librssguard/database/databasequeries.cpp b/src/librssguard/database/databasequeries.cpp index 9379f7265..41686f392 100755 --- a/src/librssguard/database/databasequeries.cpp +++ b/src/librssguard/database/databasequeries.cpp @@ -959,10 +959,8 @@ int DatabaseQueries::updateMessages(QSqlDatabase db, int account_id, const QString& url, bool force_update, - bool* any_message_changed, bool* ok) { if (messages.isEmpty()) { - *any_message_changed = false; *ok = true; return 0; } @@ -1188,8 +1186,6 @@ int DatabaseQueries::updateMessages(QSqlDatabase db, query_update.bindValue(QSL(":score"), message.m_score); query_update.bindValue(QSL(":id"), id_existing_message); - *any_message_changed = true; - if (query_update.exec()) { qDebugNN << LOGSEC_DB << "Updating message with title" @@ -1197,10 +1193,7 @@ int DatabaseQueries::updateMessages(QSqlDatabase db, << "URL" << QUOTE_W_SPACE(message.m_url) << "in DB."; - - if (!message.m_isRead) { - updated_messages++; - } + updated_messages++; } else if (query_update.lastError().isValid()) { qWarningNN << LOGSEC_DB @@ -1235,19 +1228,18 @@ int DatabaseQueries::updateMessages(QSqlDatabase db, } qDebugNN << LOGSEC_DB - << "Adding new message with title '" - << message.m_title - << "' url '" - << message.m_url - << "' to DB."; + << "Adding new message with title" + << QUOTE_W_SPACE(message.m_title) + << ", URL" + << QUOTE_W_SPACE(message.m_url) + << "to DB."; } else if (query_insert.lastError().isValid()) { qWarningNN << LOGSEC_DB - << "Failed to insert message to DB: '" - << query_insert.lastError().text() - << "' - message title is '" - << message.m_title - << "'."; + << "Failed to insert message to DB:" + << QUOTE_W_SPACE(query_insert.lastError().text()) + << "- message title is" + << QUOTE_W_SPACE_DOT(message.m_title); } query_insert.finish(); diff --git a/src/librssguard/database/databasequeries.h b/src/librssguard/database/databasequeries.h index c388d92b5..d85f7f8c1 100644 --- a/src/librssguard/database/databasequeries.h +++ b/src/librssguard/database/databasequeries.h @@ -110,7 +110,7 @@ class DatabaseQueries { static bool storeNewOauthTokens(const QSqlDatabase& db, const QString& refresh_token, int account_id); static void createOverwriteAccount(const QSqlDatabase& db, ServiceRoot* account); static int updateMessages(QSqlDatabase db, const QList& messages, const QString& feed_custom_id, - int account_id, const QString& url, bool force_update, bool* any_message_changed, bool* ok = nullptr); + int account_id, const QString& url, bool force_update, bool* ok = nullptr); static bool deleteAccount(const QSqlDatabase& db, int account_id); static bool deleteAccountData(const QSqlDatabase& db, int account_id, bool delete_messages_too); static bool cleanLabelledMessages(const QSqlDatabase& db, bool clean_read_only, Label* label); diff --git a/src/librssguard/services/abstract/feed.cpp b/src/librssguard/services/abstract/feed.cpp index 4858b01c1..ebbf86848 100755 --- a/src/librssguard/services/abstract/feed.cpp +++ b/src/librssguard/services/abstract/feed.cpp @@ -199,7 +199,6 @@ int Feed::updateMessages(const QList& messages, bool error_during_obtai << "Updating messages in DB. Main thread:" << QUOTE_W_SPACE_DOT(is_main_thread ? "true" : "false"); - bool anything_updated = false; bool ok = true; if (!messages.isEmpty()) { @@ -213,7 +212,7 @@ int Feed::updateMessages(const QList& messages, bool error_during_obtai qApp->database()->driver()->connection(QSL("feed_upd")); updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, - source(), force_update, &anything_updated, &ok); + source(), force_update, &ok); } else { qDebugNN << LOGSEC_CORE @@ -224,17 +223,17 @@ int Feed::updateMessages(const QList& messages, bool error_during_obtai setStatus(updated_messages > 0 ? Status::NewMessages : Status::Normal); updateCounts(true); - if (getParentServiceRoot()->recycleBin() != nullptr && anything_updated) { + if (getParentServiceRoot()->recycleBin() != nullptr && updated_messages > 0) { getParentServiceRoot()->recycleBin()->updateCounts(true); items_to_update.append(getParentServiceRoot()->recycleBin()); } - if (getParentServiceRoot()->importantNode() != nullptr && anything_updated) { + if (getParentServiceRoot()->importantNode() != nullptr && updated_messages > 0) { getParentServiceRoot()->importantNode()->updateCounts(true); items_to_update.append(getParentServiceRoot()->importantNode()); } - if (getParentServiceRoot()->unreadNode() != nullptr && anything_updated) { + if (getParentServiceRoot()->unreadNode() != nullptr && updated_messages > 0) { getParentServiceRoot()->unreadNode()->updateCounts(true); items_to_update.append(getParentServiceRoot()->unreadNode()); } diff --git a/src/librssguard/services/standard/standardfeed.h b/src/librssguard/services/standard/standardfeed.h index 8e73b8c7e..a14601e13 100644 --- a/src/librssguard/services/standard/standardfeed.h +++ b/src/librssguard/services/standard/standardfeed.h @@ -39,20 +39,15 @@ class StandardFeed : public Feed { explicit StandardFeed(RootItem* parent_item = nullptr); explicit StandardFeed(const StandardFeed& other); - QList contextMenuFeedsList(); - QString additionalTooltip() const; - - bool canBeDeleted() const; - bool deleteViaGui(); - - bool editViaGui(); - + virtual QList contextMenuFeedsList(); + virtual QString additionalTooltip() const; + virtual bool canBeDeleted() const; + virtual bool deleteViaGui(); + virtual bool editViaGui(); virtual QVariantHash customDatabaseData() const; virtual void setCustomDatabaseData(const QVariantHash& data); - - // Obtains data related to this feed. - Qt::ItemFlags additionalFlags() const; - bool performDragDropChange(RootItem* target_item); + virtual Qt::ItemFlags additionalFlags() const; + virtual bool performDragDropChange(RootItem* target_item); // Other getters/setters. Type type() const;