This commit is contained in:
Martin Rotter 2023-12-11 13:26:45 +01:00
parent 95c2e266e7
commit bcc715e83e
4 changed files with 22 additions and 18 deletions

View File

@ -181,6 +181,7 @@ QJsonObject Message::toJson() const {
obj.insert(QSL("id"), m_id);
obj.insert(QSL("custom_id"), m_customId);
obj.insert(QSL("custom_hash"), m_customHash);
obj.insert(QSL("feed_custom_id"), m_feedId);
obj.insert(QSL("enclosures"), Enclosures::encodeEnclosuresToJson(m_enclosures));
return obj;

View File

@ -1174,32 +1174,35 @@ QList<Message> DatabaseQueries::getUndeletedUnreadMessages(const QSqlDatabase& d
return messages;
}
QList<Message> DatabaseQueries::getFeedsSlice(const QSqlDatabase& db,
const QString& feed_custom_id,
int account_id,
bool newest_first,
bool unread_only,
int row_offset,
int row_limit) {
QList<Message> DatabaseQueries::getArticlesSlice(const QSqlDatabase& db,
const QString& feed_custom_id,
int account_id,
bool newest_first,
bool unread_only,
int row_offset,
int row_limit) {
QList<Message> messages;
QSqlQuery q(db);
QString feed_clause = !feed_custom_id.isEmpty() ? QSL("feed = :feed AND") : QString();
q.setForwardOnly(true);
q.prepare(QSL("SELECT %1 "
"FROM Messages "
"WHERE is_deleted = 0 AND "
" is_pdeleted = 0 AND "
" is_read = :is_read AND "
" feed = :feed AND "
" %3 "
" account_id = :account_id "
"ORDER BY Messages.date_created %2 "
"LIMIT :row_limit OFFSET :row_offset;")
.arg(messageTableAttributes(true, db.driverName() == QSL(APP_DB_SQLITE_DRIVER)).values().join(QSL(", ")),
newest_first ? QSL("DESC") : QSL("ASC")));
q.bindValue(QSL(":feed"), feed_custom_id);
newest_first ? QSL("DESC") : QSL("ASC"),
feed_clause));
q.bindValue(QSL(":account_id"), account_id);
q.bindValue(QSL(":row_limit"), row_limit);
q.bindValue(QSL(":row_offset"), row_offset);
q.bindValue(QSL(":feed"), QSL("feed"));
if (unread_only) {
q.bindValue(QSL(":is_read"), 0);

View File

@ -118,13 +118,13 @@ class DatabaseQueries {
static QList<Message> getUndeletedMessagesForBin(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static QList<Message> getUndeletedMessagesForAccount(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static QList<Message> getFeedsSlice(const QSqlDatabase& db,
const QString& feed_custom_id,
int account_id,
bool newest_first,
bool unread_only,
int row_offset,
int row_limit);
static QList<Message> getArticlesSlice(const QSqlDatabase& db,
const QString& feed_custom_id,
int account_id,
bool newest_first,
bool unread_only,
int row_offset,
int row_limit);
// Custom ID accumulators.
static QStringList bagOfMessages(const QSqlDatabase& db, ServiceRoot::BagOfMessages bag, const Feed* feed);

View File

@ -81,7 +81,7 @@ ApiResponse ApiServer::processArticlesFromFeed(const QJsonValue& req) const {
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
QList<Message> msgs =
DatabaseQueries::getFeedsSlice(database, feed_id, account_id, newest_first, unread_only, row_offset, row_limit);
DatabaseQueries::getArticlesSlice(database, feed_id, account_id, newest_first, unread_only, row_offset, row_limit);
QJsonArray msgs_json_array;
for (const Message& msg : msgs) {