rssguard/src/librssguard/database/databasequeries.h

446 lines
22 KiB
C
Raw Normal View History

// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef DATABASEQUERIES_H
#define DATABASEQUERIES_H
#include "core/messagefilter.h"
#include "definitions/typedefs.h"
2021-02-26 14:26:53 +01:00
#include "miscellaneous/application.h"
2021-03-03 11:01:41 +01:00
#include "miscellaneous/iconfactory.h"
2021-02-26 12:35:57 +01:00
#include "miscellaneous/textfactory.h"
2020-06-23 13:55:00 +02:00
#include "services/abstract/category.h"
2020-10-07 16:10:57 +02:00
#include "services/abstract/label.h"
2024-03-19 10:31:49 +01:00
#include "services/abstract/rootitem.h"
2023-08-09 12:41:48 +02:00
#include "services/abstract/search.h"
2021-02-26 14:00:13 +01:00
#include "services/abstract/serviceroot.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QMultiMap>
2020-06-23 13:38:25 +02:00
#include <QSqlError>
#include <QSqlQuery>
class RSSGUARD_DLLSPEC DatabaseQueries {
2017-09-19 10:18:21 +02:00
public:
2023-06-14 10:24:30 +02:00
static QMap<int, QString> messageTableAttributes(bool only_msg_table, bool is_sqlite);
2017-09-19 10:18:21 +02:00
2021-03-01 09:16:11 +01:00
// Custom data serializers.
static QString serializeCustomData(const QVariantHash& data);
static QVariantHash deserializeCustomData(const QString& data);
2020-10-07 16:10:57 +02:00
// Label operators.
static bool isLabelAssignedToMessage(const QSqlDatabase& db, Label* label, const Message& msg);
static bool deassignLabelFromMessage(const QSqlDatabase& db, Label* label, const Message& msg);
static bool assignLabelToMessage(const QSqlDatabase& db, Label* label, const Message& msg);
static bool setLabelsForMessage(const QSqlDatabase& db, const QList<Label*>& labels, const Message& msg);
2021-03-04 09:19:22 +01:00
static QList<Label*> getLabelsForAccount(const QSqlDatabase& db, int account_id);
2022-12-03 09:28:26 +01:00
static QList<Label*> getLabelsForMessage(const QSqlDatabase& db,
const Message& msg,
2023-06-01 09:27:32 +02:00
const QList<Label*>& installed_labels);
2020-10-07 20:22:50 +02:00
static bool updateLabel(const QSqlDatabase& db, Label* label);
static bool deleteLabel(const QSqlDatabase& db, Label* label);
2020-10-07 16:10:57 +02:00
static bool createLabel(const QSqlDatabase& db, Label* label, int account_id);
2023-08-09 12:41:48 +02:00
// Probe operators.
static void createProbe(const QSqlDatabase& db, Search* probe, int account_id);
static QList<Search*> getProbesForAccount(const QSqlDatabase& db, int account_id);
2023-08-09 13:41:36 +02:00
static void deleteProbe(const QSqlDatabase& db, Search* probe);
2023-08-09 14:20:41 +02:00
static void updateProbe(const QSqlDatabase& db, Search* probe);
2023-08-09 12:41:48 +02:00
// Message operators.
2023-08-15 10:14:27 +02:00
static void markProbeReadUnread(const QSqlDatabase& db, Search* probe, RootItem::ReadStatus read);
static bool markLabelledMessagesReadUnread(const QSqlDatabase& db, Label* label, RootItem::ReadStatus read);
static bool markImportantMessagesReadUnread(const QSqlDatabase& db, int account_id, RootItem::ReadStatus read);
2021-03-31 10:40:44 +02:00
static bool markUnreadMessagesRead(const QSqlDatabase& db, int account_id);
2019-04-12 07:35:28 +02:00
static bool markMessagesReadUnread(const QSqlDatabase& db, const QStringList& ids, RootItem::ReadStatus read);
2023-12-19 07:22:54 +01:00
static void markMessagesReadUnreadImportant(const QSqlDatabase& db,
int account_id,
const QStringList& custom_ids,
RootItem::ReadStatus read,
RootItem::Importance important);
2019-04-12 07:35:28 +02:00
static bool markMessageImportant(const QSqlDatabase& db, int id, RootItem::Importance importance);
2022-12-03 09:28:26 +01:00
static bool markFeedsReadUnread(const QSqlDatabase& db,
const QStringList& ids,
int account_id,
RootItem::ReadStatus read);
2019-04-12 07:35:28 +02:00
static bool markBinReadUnread(const QSqlDatabase& db, int account_id, RootItem::ReadStatus read);
static bool markAccountReadUnread(const QSqlDatabase& db, int account_id, RootItem::ReadStatus read);
static bool switchMessagesImportance(const QSqlDatabase& db, const QStringList& ids);
static bool permanentlyDeleteMessages(const QSqlDatabase& db, const QStringList& ids);
static bool deleteOrRestoreMessagesToFromBin(const QSqlDatabase& db, const QStringList& ids, bool deleted);
static bool restoreBin(const QSqlDatabase& db, int account_id);
2017-09-19 10:18:21 +02:00
// Purge database.
2024-01-16 10:38:38 +01:00
static bool removeUnwantedArticlesFromFeed(const QSqlDatabase& db,
const Feed* feed,
2024-01-15 14:51:39 +01:00
const Feed::ArticleIgnoreLimit& feed_setup,
const Feed::ArticleIgnoreLimit& app_setup);
2020-12-13 20:30:43 +01:00
static bool purgeMessage(const QSqlDatabase& db, int message_id);
2019-04-12 07:35:28 +02:00
static bool purgeImportantMessages(const QSqlDatabase& db);
static bool purgeReadMessages(const QSqlDatabase& db);
static bool purgeOldMessages(const QSqlDatabase& db, int older_than_days);
static bool purgeRecycleBin(const QSqlDatabase& db);
static bool purgeMessagesFromBin(const QSqlDatabase& db, bool clear_only_read, int account_id);
static bool purgeLeftoverMessages(const QSqlDatabase& db, int account_id);
2017-09-19 10:18:21 +02:00
// Counts of unread/all messages.
static QMap<QString, ArticleCounts> getMessageCountsForCategory(const QSqlDatabase& db,
const QString& custom_id,
int account_id,
bool include_total_counts,
bool* ok = nullptr);
static QMap<QString, ArticleCounts> getMessageCountsForAccount(const QSqlDatabase& db,
int account_id,
bool include_total_counts,
bool* ok = nullptr);
static ArticleCounts getMessageCountsForFeed(const QSqlDatabase& db,
const QString& feed_custom_id,
int account_id,
bool* ok = nullptr);
static ArticleCounts getMessageCountsForLabel(const QSqlDatabase& db,
Label* label,
int account_id,
bool* ok = nullptr);
2023-08-15 10:14:27 +02:00
static ArticleCounts getMessageCountsForProbe(const QSqlDatabase& db, Search* probe, int account_id);
static QMap<QString, ArticleCounts> getMessageCountsForAllLabels(const QSqlDatabase& db,
int account_id,
bool* ok = nullptr);
2023-06-12 07:44:08 +02:00
static QMap<QString, ArticleCounts> getCountOfAssignedLabelsToMessages(const QSqlDatabase& db,
const QList<Message>& messages,
int account_id,
bool* ok = nullptr);
static ArticleCounts getImportantMessageCounts(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
2021-03-31 09:59:33 +02:00
static int getUnreadMessageCounts(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static ArticleCounts getMessageCountsForBin(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
2017-09-19 10:18:21 +02:00
// Get messages (for newspaper view for example).
2023-08-16 13:13:46 +02:00
static QList<Message> getUndeletedMessagesForProbe(const QSqlDatabase& db, const Search* probe);
static QList<Message> getUndeletedMessagesWithLabel(const QSqlDatabase& db, const Label* label, bool* ok = nullptr);
static QList<Message> getUndeletedLabelledMessages(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static QList<Message> getUndeletedImportantMessages(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
2021-03-31 09:59:33 +02:00
static QList<Message> getUndeletedUnreadMessages(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
2022-12-03 09:28:26 +01:00
static QList<Message> getUndeletedMessagesForFeed(const QSqlDatabase& db,
const QString& feed_custom_id,
int account_id,
bool* ok = nullptr);
2019-04-12 07:35:28 +02:00
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);
2017-09-19 10:18:21 +02:00
2023-12-11 13:26:45 +01:00
static QList<Message> getArticlesSlice(const QSqlDatabase& db,
const QString& feed_custom_id,
int account_id,
bool newest_first,
bool unread_only,
bool starred_only,
2023-12-13 07:21:30 +01:00
qint64 start_after_article_date,
2023-12-11 13:26:45 +01:00
int row_offset,
int row_limit);
2023-12-11 10:44:24 +01:00
2017-09-19 10:18:21 +02:00
// Custom ID accumulators.
2021-07-14 14:52:27 +02:00
static QStringList bagOfMessages(const QSqlDatabase& db, ServiceRoot::BagOfMessages bag, const Feed* feed);
2021-07-14 14:46:45 +02:00
static QHash<QString, QStringList> bagsOfMessages(const QSqlDatabase& db, const QList<Label*>& labels);
static QStringList customIdsOfMessagesFromLabel(const QSqlDatabase& db,
Label* label,
RootItem::ReadStatus target_read,
bool* ok = nullptr);
2023-08-15 10:14:27 +02:00
static QStringList customIdsOfMessagesFromProbe(const QSqlDatabase& db,
Search* probe,
RootItem::ReadStatus target_read);
static QStringList customIdsOfImportantMessages(const QSqlDatabase& db,
RootItem::ReadStatus target_read,
int account_id,
bool* ok = nullptr);
2023-06-01 09:27:32 +02:00
static QStringList customIdsOfUnreadMessages(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
static QStringList customIdsOfMessagesFromAccount(const QSqlDatabase& db,
RootItem::ReadStatus target_read,
int account_id,
bool* ok = nullptr);
static QStringList customIdsOfMessagesFromBin(const QSqlDatabase& db,
RootItem::ReadStatus target_read,
int account_id,
bool* ok = nullptr);
2022-12-03 09:28:26 +01:00
static QStringList customIdsOfMessagesFromFeed(const QSqlDatabase& db,
const QString& feed_custom_id,
RootItem::ReadStatus target_read,
2022-12-03 09:28:26 +01:00
int account_id,
bool* ok = nullptr);
2017-09-19 10:18:21 +02:00
// Common account methods.
2022-12-03 09:28:26 +01:00
template <typename T>
2021-02-26 12:35:57 +01:00
static QList<ServiceRoot*> getAccounts(const QSqlDatabase& db, const QString& code, bool* ok = nullptr);
2021-02-26 14:11:35 +01:00
2023-08-09 12:41:48 +02:00
template <typename Categ, typename Fee>
static void loadRootFromDatabase(ServiceRoot* root);
2021-03-01 09:16:11 +01:00
static bool storeNewOauthTokens(const QSqlDatabase& db, const QString& refresh_token, int account_id);
2021-02-26 12:35:57 +01:00
static void createOverwriteAccount(const QSqlDatabase& db, ServiceRoot* account);
2021-06-25 13:36:23 +02:00
// Returns counts of updated messages <unread, all>.
static UpdatedArticles updateMessages(const QSqlDatabase& db,
2022-12-03 09:28:26 +01:00
QList<Message>& messages,
Feed* feed,
bool force_update,
QMutex* db_mutex,
2022-12-03 09:28:26 +01:00
bool* ok = nullptr);
2022-03-08 07:42:46 +01:00
static bool deleteAccount(const QSqlDatabase& db, ServiceRoot* account);
2022-12-03 09:28:26 +01:00
static bool deleteAccountData(const QSqlDatabase& db,
int account_id,
bool delete_messages_too,
bool delete_labels_too);
static bool cleanLabelledMessages(const QSqlDatabase& db, bool clean_read_only, Label* label);
static void cleanProbedMessages(const QSqlDatabase& db, bool clean_read_only, Search* probe);
static bool cleanImportantMessages(const QSqlDatabase& db, bool clean_read_only, int account_id);
2021-03-31 10:40:44 +02:00
static bool cleanUnreadMessages(const QSqlDatabase& db, int account_id);
2019-04-12 07:35:28 +02:00
static bool cleanFeeds(const QSqlDatabase& db, const QStringList& ids, bool clean_read_only, int account_id);
static void storeAccountTree(const QSqlDatabase& db, RootItem* tree_root, int account_id);
static void createOverwriteFeed(const QSqlDatabase& db, Feed* feed, int account_id, int new_parent_id);
2022-03-16 08:14:50 +01:00
static void createOverwriteCategory(const QSqlDatabase& db, Category* category, int account_id, int new_parent_id);
static bool deleteFeed(const QSqlDatabase& db, Feed* feed, int account_id);
static bool deleteCategory(const QSqlDatabase& db, Category* category);
2020-06-23 13:55:00 +02:00
2023-08-09 12:41:48 +02:00
template <typename T>
static Assignment getCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
2017-09-19 10:18:21 +02:00
2022-12-03 09:28:26 +01:00
template <typename T>
static Assignment getFeeds(const QSqlDatabase& db,
const QList<MessageFilter*>& global_filters,
int account_id,
bool* ok = nullptr);
2020-06-23 13:38:25 +02:00
// Item order methods.
static void moveItem(RootItem* item, bool move_top, bool move_bottom, int move_index, const QSqlDatabase& db);
// Message filters operators.
static bool purgeLeftoverMessageFilterAssignments(const QSqlDatabase& db, int account_id);
2020-07-09 11:51:48 +02:00
static MessageFilter* addMessageFilter(const QSqlDatabase& db, const QString& title, const QString& script);
static void removeMessageFilter(const QSqlDatabase& db, int filter_id, bool* ok = nullptr);
static void removeMessageFilterAssignments(const QSqlDatabase& db, int filter_id, bool* ok = nullptr);
static QList<MessageFilter*> getMessageFilters(const QSqlDatabase& db, bool* ok = nullptr);
static QMultiMap<QString, int> messageFiltersInFeeds(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
2022-12-03 09:28:26 +01:00
static void assignMessageFilterToFeed(const QSqlDatabase& db,
const QString& feed_custom_id,
int filter_id,
int account_id,
bool* ok = nullptr);
static void updateMessageFilter(const QSqlDatabase& db, MessageFilter* filter, bool* ok = nullptr);
2022-12-03 09:28:26 +01:00
static void removeMessageFilterFromFeed(const QSqlDatabase& db,
const QString& feed_custom_id,
int filter_id,
int account_id,
bool* ok = nullptr);
2017-09-19 10:18:21 +02:00
// Gmail account.
2021-03-22 09:45:25 +01:00
static QStringList getAllGmailRecipients(const QSqlDatabase& db, int account_id);
2017-09-19 10:18:21 +02:00
private:
2018-01-03 07:47:55 +01:00
static QString unnulifyString(const QString& str);
2020-08-10 14:47:29 +02:00
explicit DatabaseQueries() = default;
};
2022-12-03 09:28:26 +01:00
template <typename T>
2021-02-26 12:35:57 +01:00
QList<ServiceRoot*> DatabaseQueries::getAccounts(const QSqlDatabase& db, const QString& code, bool* ok) {
QSqlQuery query(db);
QList<ServiceRoot*> roots;
if (query.exec(QSL("SELECT * FROM Accounts WHERE type = '%1';").arg(code))) {
while (query.next()) {
ServiceRoot* root = new T();
// Load common data.
root->setAccountId(query.value(QSL("id")).toInt());
root->setSortOrder(query.value(QSL("ordr")).toInt());
2021-02-26 12:35:57 +01:00
QNetworkProxy proxy(QNetworkProxy::ProxyType(query.value(QSL("proxy_type")).toInt()),
query.value(QSL("proxy_host")).toString(),
query.value(QSL("proxy_port")).toInt(),
query.value(QSL("proxy_username")).toString(),
TextFactory::decrypt(query.value(QSL("proxy_password")).toString()));
root->setNetworkProxy(proxy);
2021-03-01 09:16:11 +01:00
root->setCustomDatabaseData(deserializeCustomData(query.value(QSL("custom_data")).toString()));
2021-02-26 12:35:57 +01:00
roots.append(root);
}
if (ok != nullptr) {
*ok = true;
}
}
else {
2022-12-03 09:28:26 +01:00
qWarningNN << LOGSEC_DB << "Loading of accounts with code" << QUOTE_W_SPACE(code)
<< "failed with error:" << QUOTE_W_SPACE_DOT(query.lastError().text());
2021-02-26 12:35:57 +01:00
if (ok != nullptr) {
*ok = false;
}
}
return roots;
}
2023-08-09 12:41:48 +02:00
template <typename T>
Assignment DatabaseQueries::getCategories(const QSqlDatabase& db, int account_id, bool* ok) {
2020-06-23 13:55:00 +02:00
Assignment categories;
// Obtain data for categories from the database.
QSqlQuery query_categories(db);
query_categories.setForwardOnly(true);
query_categories.prepare(QSL("SELECT * FROM Categories WHERE account_id = :account_id;"));
query_categories.bindValue(QSL(":account_id"), account_id);
if (!query_categories.exec()) {
2022-12-03 09:28:26 +01:00
qFatal("Query for obtaining categories failed. Error message: '%s'.",
qPrintable(query_categories.lastError().text()));
2020-06-23 13:55:00 +02:00
if (ok != nullptr) {
*ok = false;
}
}
else {
if (ok != nullptr) {
*ok = true;
}
}
while (query_categories.next()) {
AssignmentItem pair;
pair.first = query_categories.value(CAT_DB_PARENT_ID_INDEX).toInt();
2021-03-03 11:01:41 +01:00
pair.second = new T();
auto* cat = static_cast<Category*>(pair.second);
cat->setId(query_categories.value(CAT_DB_ID_INDEX).toInt());
cat->setSortOrder(query_categories.value(CAT_DB_ORDER_INDEX).toInt());
2021-03-03 11:01:41 +01:00
cat->setCustomId(query_categories.value(CAT_DB_CUSTOM_ID_INDEX).toString());
if (cat->customId().isEmpty()) {
cat->setCustomId(QString::number(cat->id()));
}
cat->setTitle(query_categories.value(CAT_DB_TITLE_INDEX).toString());
cat->setDescription(query_categories.value(CAT_DB_DESCRIPTION_INDEX).toString());
2021-03-30 08:55:15 +02:00
cat->setCreationDate(TextFactory::parseDateTime(query_categories.value(CAT_DB_DCREATED_INDEX).value<qint64>()));
2021-03-03 11:01:41 +01:00
cat->setIcon(qApp->icons()->fromByteArray(query_categories.value(CAT_DB_ICON_INDEX).toByteArray()));
2020-06-23 13:55:00 +02:00
categories << pair;
}
return categories;
}
2022-12-03 09:28:26 +01:00
template <typename T>
2021-01-29 10:40:32 +01:00
Assignment DatabaseQueries::getFeeds(const QSqlDatabase& db,
const QList<MessageFilter*>& global_filters,
int account_id,
bool* ok) {
2020-06-23 13:38:25 +02:00
Assignment feeds;
// All categories are now loaded.
QSqlQuery query(db);
auto filters_in_feeds = messageFiltersInFeeds(db, account_id);
2020-06-23 13:38:25 +02:00
query.setForwardOnly(true);
query.prepare(QSL("SELECT * FROM Feeds WHERE account_id = :account_id;"));
query.bindValue(QSL(":account_id"), account_id);
2020-06-23 13:38:25 +02:00
if (!query.exec()) {
qFatal("Query for obtaining feeds failed. Error message: '%s'.", qPrintable(query.lastError().text()));
2020-06-23 13:38:25 +02:00
if (ok != nullptr) {
*ok = false;
}
}
else {
if (ok != nullptr) {
*ok = true;
}
}
while (query.next()) {
2020-06-23 13:38:25 +02:00
AssignmentItem pair;
pair.first = query.value(FDS_DB_CATEGORY_INDEX).toInt();
2020-06-23 13:38:25 +02:00
2021-03-03 11:01:41 +01:00
Feed* feed = new T();
// Load common data.
feed->setTitle(query.value(FDS_DB_TITLE_INDEX).toString());
feed->setId(query.value(FDS_DB_ID_INDEX).toInt());
feed->setSortOrder(query.value(FDS_DB_ORDER_INDEX).toInt());
2021-03-03 11:01:41 +01:00
feed->setSource(query.value(FDS_DB_SOURCE_INDEX).toString());
feed->setCustomId(query.value(FDS_DB_CUSTOM_ID_INDEX).toString());
if (feed->customId().isEmpty()) {
feed->setCustomId(QString::number(feed->id()));
}
feed->setDescription(QString::fromUtf8(query.value(FDS_DB_DESCRIPTION_INDEX).toByteArray()));
2021-03-30 08:55:15 +02:00
feed->setCreationDate(TextFactory::parseDateTime(query.value(FDS_DB_DCREATED_INDEX).value<qint64>()));
2021-03-03 11:01:41 +01:00
feed->setIcon(qApp->icons()->fromByteArray(query.value(FDS_DB_ICON_INDEX).toByteArray()));
feed->setAutoUpdateType(static_cast<Feed::AutoUpdateType>(query.value(FDS_DB_UPDATE_TYPE_INDEX).toInt()));
2022-09-15 14:28:48 +02:00
feed->setAutoUpdateInterval(query.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt());
2022-01-18 09:32:16 +01:00
feed->setIsSwitchedOff(query.value(FDS_DB_IS_OFF_INDEX).toBool());
2022-12-03 09:28:26 +01:00
feed->setIsQuiet(query.value(FDS_DB_IS_QUIET_INDEX).toBool());
feed->setIsRtl(query.value(FDS_DB_IS_RTL_INDEX).toBool());
2024-01-15 09:37:43 +01:00
Feed::ArticleIgnoreLimit art;
art.m_addAnyArticlesToDb = query.value(FDS_DB_ADD_ANY_DATETIME_ARTICLES_INDEX).toBool();
qint64 time_to_avoid = query.value(FDS_DB_DATETIME_TO_AVOID_INDEX).value<qint64>();
if (time_to_avoid > 10000) {
2024-01-15 09:37:43 +01:00
art.m_dtToAvoid = TextFactory::parseDateTime(time_to_avoid);
}
else {
2024-01-15 09:37:43 +01:00
art.m_hoursToAvoid = time_to_avoid;
}
2024-01-15 14:51:39 +01:00
art.m_customizeLimitting = query.value(FDS_DB_KEEP_CUSTOMIZE).toBool();
2024-01-15 11:35:53 +01:00
art.m_keepCountOfArticles = query.value(FDS_DB_KEEP_ARTICLES_COUNT).toInt();
art.m_doNotRemoveUnread = query.value(FDS_DB_KEEP_UNREAD_ARTICLES).toBool();
art.m_doNotRemoveStarred = query.value(FDS_DB_KEEP_STARRED_ARTICLES).toBool();
art.m_moveToBinDontPurge = query.value(RECYCLE_ARTICLE_DONT_PURGE).toBool();
2024-01-15 09:37:43 +01:00
feed->setArticleIgnoreLimit(art);
2022-01-18 09:32:16 +01:00
feed->setOpenArticlesDirectly(query.value(FDS_DB_OPEN_ARTICLES_INDEX).toBool());
2021-03-03 11:01:41 +01:00
2022-12-03 09:28:26 +01:00
qDebugNN << LOGSEC_CORE << "Custom ID of feed when loading from DB is" << QUOTE_W_SPACE_DOT(feed->customId());
2020-06-23 13:38:25 +02:00
2021-03-02 14:30:13 +01:00
// Load custom data.
2022-01-18 09:32:16 +01:00
feed->setCustomDatabaseData(deserializeCustomData(query.value(FDS_DB_CUSTOM_DATA_INDEX).toString()));
2021-03-02 14:30:13 +01:00
if (filters_in_feeds.contains(feed->customId())) {
auto all_filters_for_this_feed = filters_in_feeds.values(feed->customId());
for (MessageFilter* fltr : global_filters) {
if (all_filters_for_this_feed.contains(fltr->id())) {
feed->appendMessageFilter(fltr);
}
}
}
2020-06-23 13:38:25 +02:00
pair.second = feed;
feeds << pair;
}
return feeds;
}
2023-08-09 12:41:48 +02:00
template <typename Categ, typename Fee>
void DatabaseQueries::loadRootFromDatabase(ServiceRoot* root) {
2021-03-05 12:46:03 +01:00
QSqlDatabase database = qApp->database()->driver()->connection(root->metaObject()->className());
2021-02-26 14:11:35 +01:00
Assignment categories = DatabaseQueries::getCategories<Categ>(database, root->accountId());
2021-02-26 14:26:53 +01:00
Assignment feeds = DatabaseQueries::getFeeds<Fee>(database, qApp->feedReader()->messageFilters(), root->accountId());
2021-03-04 09:19:22 +01:00
auto labels = DatabaseQueries::getLabelsForAccount(database, root->accountId());
2023-08-09 12:41:48 +02:00
auto probes = DatabaseQueries::getProbesForAccount(database, root->accountId());
2021-02-26 14:11:35 +01:00
2023-08-09 12:41:48 +02:00
root->performInitialAssembly(categories, feeds, labels, probes);
2021-02-26 14:11:35 +01:00
}
#endif // DATABASEQUERIES_H