Only mark episodes as read/new on new feeds, not on existing ones

This commit is contained in:
Bart De Vries 2021-04-09 20:28:36 +02:00
parent 056a7b7835
commit 26986616c7
1 changed files with 16 additions and 14 deletions

View File

@ -140,20 +140,22 @@ void Fetcher::processFeed(Syndication::FeedPtr feed, const QString &url)
processEntry(entry, url, isNewFeed);
}
// Now mark the appropriate number of recent entries "new" and "read" for new feeds
query.prepare(QStringLiteral("SELECT * FROM Entries WHERE feed=:feed ORDER BY updated DESC LIMIT :recentNew;"));
query.bindValue(QStringLiteral(":feed"), url);
query.bindValue(QStringLiteral(":recentNew"), AlligatorSettings::self()->numberNewEpisodes());
Database::instance().execute(query);
QSqlQuery updateQuery;
while (query.next()) {
qDebug() << "new" << query.value(QStringLiteral("id")).toString();
updateQuery.prepare(QStringLiteral("UPDATE Entries SET read=:read, new=:new WHERE id=:id AND feed=:feed;"));
updateQuery.bindValue(QStringLiteral(":read"), false);
updateQuery.bindValue(QStringLiteral(":new"), true);
updateQuery.bindValue(QStringLiteral(":feed"), url);
updateQuery.bindValue(QStringLiteral(":id"), query.value(QStringLiteral("id")).toString());
Database::instance().execute(updateQuery);
// Now mark the appropriate number of recent entries "new" and "read" for new feeds only
if (isNewFeed) {
query.prepare(QStringLiteral("SELECT * FROM Entries WHERE feed=:feed ORDER BY updated DESC LIMIT :recentNew;"));
query.bindValue(QStringLiteral(":feed"), url);
query.bindValue(QStringLiteral(":recentNew"), AlligatorSettings::self()->numberNewEpisodes());
Database::instance().execute(query);
QSqlQuery updateQuery;
while (query.next()) {
qDebug() << "Marked as new:" << query.value(QStringLiteral("id")).toString();
updateQuery.prepare(QStringLiteral("UPDATE Entries SET read=:read, new=:new WHERE id=:id AND feed=:feed;"));
updateQuery.bindValue(QStringLiteral(":read"), false);
updateQuery.bindValue(QStringLiteral(":new"), true);
updateQuery.bindValue(QStringLiteral(":feed"), url);
updateQuery.bindValue(QStringLiteral(":id"), query.value(QStringLiteral("id")).toString());
Database::instance().execute(updateQuery);
}
}
Q_EMIT feedUpdated(url);