make sure unread feeditem is updated when deleting stuff

This commit is contained in:
Martin Rotter 2021-04-01 06:06:16 +02:00
parent 19ba70fd4f
commit 1c0c5aed92
6 changed files with 28 additions and 37 deletions

View File

@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" />
<releases>
<release version="3.9.0" date="2021-03-31"/>
<release version="3.9.0" date="2021-04-01"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -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();
}

View File

@ -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();

View File

@ -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<Message>& 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);

View File

@ -199,7 +199,6 @@ int Feed::updateMessages(const QList<Message>& 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<Message>& 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<Message>& 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());
}

View File

@ -39,20 +39,15 @@ class StandardFeed : public Feed {
explicit StandardFeed(RootItem* parent_item = nullptr);
explicit StandardFeed(const StandardFeed& other);
QList<QAction*> contextMenuFeedsList();
QString additionalTooltip() const;
bool canBeDeleted() const;
bool deleteViaGui();
bool editViaGui();
virtual QList<QAction*> 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;