Skip to content

Commit

Permalink
option to purge individual feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Jan 8, 2025
1 parent fe4f991 commit 07740a0
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 34 deletions.
20 changes: 20 additions & 0 deletions src/librssguard/core/feedsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,26 @@ bool FeedsModel::markItemCleared(RootItem* item, bool clean_read_only) {
return true;
}

bool FeedsModel::purgeArticles(const QList<Feed*>& feeds) {
auto database = qApp->database()->driver()->connection(metaObject()->className());

try {
bool anything_purged = DatabaseQueries::purgeFeedArticles(database, feeds);

if (anything_purged) {
reloadCountsOfWholeModel();
emit reloadMessageListRequested(false);
return true;
}
}
catch (const ApplicationException& ex) {
qCriticalNN << LOGSEC_CORE
<< "Purging of articles from feeds failed with error:" << QUOTE_W_SPACE_DOT(ex.message());
}

return false;
}

QVariant FeedsModel::data(const QModelIndex& index, int role) const {
switch (role) {
case Qt::ItemDataRole::FontRole: {
Expand Down
1 change: 1 addition & 0 deletions src/librssguard/core/feedsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class RSSGUARD_DLLSPEC FeedsModel : public QAbstractItemModel {
// Feeds operations.
bool markItemRead(RootItem* item, RootItem::ReadStatus read);
bool markItemCleared(RootItem* item, bool clean_read_only);
bool purgeArticles(const QList<Feed *> &feeds);

// Signals that properties (probably counts)
// of ALL items have changed.
Expand Down
27 changes: 18 additions & 9 deletions src/librssguard/database/databasequeries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,18 +634,27 @@ bool DatabaseQueries::removeUnwantedArticlesFromFeed(const QSqlDatabase& db,
return rows_deleted > 0;
}

bool DatabaseQueries::purgeFeedMessages(const QSqlDatabase& database, const Feed* feed) {
bool DatabaseQueries::purgeFeedArticles(const QSqlDatabase& database, const QList<Feed*>& feeds) {
QSqlQuery q(database);

q.setForwardOnly(true);
q.prepare(QSL("DELETE FROM Messages "
"WHERE "
" Messages.account_id = :account_id AND "
" Messages.feed = :feed AND "
" Messages.is_important = 0"));
auto feed_clauses = boolinq::from(feeds)
.select([](Feed* feed) {
return QSL("("
"Messages.feed = '%1' AND "
"Messages.account_id = %2 AND "
"Messages.is_important = 0"
")")
.arg(feed->customId(), QString::number(feed->getParentServiceRoot()->accountId()));
})
.toStdList();

q.bindValue(QSL(":feed"), feed->customId());
q.bindValue(QSL(":account_id"), feed->getParentServiceRoot()->accountId());
qDebugNN << feed_clauses;

QStringList feed_str_clauses = FROM_STD_LIST(QStringList, feed_clauses);
QString feed_clause = feed_str_clauses.join(QSL(" OR "));

q.setForwardOnly(true);
q.prepare(QSL("DELETE FROM Messages WHERE %1;").arg(feed_clause));

if (!q.exec()) {
throw ApplicationException(q.lastError().text());
Expand Down
2 changes: 1 addition & 1 deletion src/librssguard/database/databasequeries.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class RSSGUARD_DLLSPEC DatabaseQueries {
const Feed::ArticleIgnoreLimit& feed_setup,
const Feed::ArticleIgnoreLimit& app_setup);

static bool purgeFeedMessages(const QSqlDatabase& database, const Feed* feed);
static bool purgeFeedArticles(const QSqlDatabase& database, const QList<Feed*>& feeds);
static bool purgeMessage(const QSqlDatabase& db, int message_id);
static bool purgeImportantMessages(const QSqlDatabase& db);
static bool purgeReadMessages(const QSqlDatabase& db);
Expand Down
2 changes: 1 addition & 1 deletion src/librssguard/gui/dialogs/formmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ void FormMain::updateFeedButtonsAvailability() {
m_ui->m_actionBackupDatabaseSettings->setEnabled(!critical_action_running);
m_ui->m_actionCleanupDatabase->setEnabled(!critical_action_running);
m_ui->m_actionClearSelectedItems->setEnabled(anything_selected);
m_ui->m_actionPurgeSelectedItems->setEnabled(feed_selected);
m_ui->m_actionPurgeSelectedItems->setEnabled(feed_selected || category_selected || service_selected);
m_ui->m_actionDeleteSelectedItem->setEnabled(!critical_action_running && anything_selected);
m_ui->m_actionEditSelectedItem->setEnabled(!critical_action_running && anything_selected);
m_ui->m_actionEditChildFeeds->setEnabled(!critical_action_running && (service_selected || category_selected));
Expand Down
5 changes: 2 additions & 3 deletions src/librssguard/gui/feedsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ void FeedsView::purgeSelectedFeeds() {
return;
}

for (auto* it : selectedFeeds(true)) {
it->purgeArticles();
}
m_sourceModel->purgeArticles(selectedFeeds(true));
}

void FeedsView::clearAllItems() {
Expand Down Expand Up @@ -989,6 +987,7 @@ QMenu* FeedsView::initializeContextMenuFeeds(RootItem* clicked_item) {
<< qApp->mainForm()->m_ui->m_actionCopyUrlSelectedFeed
<< qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsRead
<< qApp->mainForm()->m_ui->m_actionMarkSelectedItemsAsUnread
<< qApp->mainForm()->m_ui->m_actionPurgeSelectedItems
<< qApp->mainForm()->m_ui->m_actionDeleteSelectedItem);

auto cat_add = clicked_item->getParentServiceRoot()->supportsCategoryAdding();
Expand Down
18 changes: 0 additions & 18 deletions src/librssguard/services/abstract/feed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,6 @@ QVariant Feed::data(int column, int role) const {
}
}

void Feed::purgeArticles() {
auto database = qApp->database()->driver()->connection(metaObject()->className());

try {
bool anything_purged = DatabaseQueries::purgeFeedMessages(database, this);

if (anything_purged) {
getParentServiceRoot()->updateCounts(true);
getParentServiceRoot()->itemChanged(getParentServiceRoot()->getSubTree());
getParentServiceRoot()->requestReloadMessageList(false);
}
}
catch (const ApplicationException& ex) {
qCriticalNN << LOGSEC_CORE << "Purging of articles from feed" << QUOTE_W_SPACE(customId())
<< "failed with error:" << QUOTE_W_SPACE_DOT(ex.message());
}
}

int Feed::autoUpdateInterval() const {
return m_autoUpdateInterval;
}
Expand Down
2 changes: 0 additions & 2 deletions src/librssguard/services/abstract/feed.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ class RSSGUARD_DLLSPEC Feed : public RootItem {
virtual bool isFetching() const;
virtual QVariant data(int column, int role) const;

void purgeArticles();

void setCountOfAllMessages(int count_all_messages);
void setCountOfUnreadMessages(int count_unread_messages);

Expand Down

0 comments on commit 07740a0

Please sign in to comment.