preparations for #746
This commit is contained in:
parent
09e6f55dce
commit
806cb57ccd
4 changed files with 39 additions and 29 deletions
|
@ -239,11 +239,7 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
|
|||
QJSEngine filter_engine;
|
||||
|
||||
// Create JavaScript communication wrapper for the message.
|
||||
MessageObject msg_obj(&database,
|
||||
feed->customId(),
|
||||
feed->getParentServiceRoot()->accountId(),
|
||||
feed->getParentServiceRoot()->labelsNode()->labels(),
|
||||
true);
|
||||
MessageObject msg_obj(&database, feed, feed->getParentServiceRoot(), true);
|
||||
|
||||
MessageFilter::initializeFilteringEngine(filter_engine, &msg_obj);
|
||||
|
||||
|
@ -253,6 +249,8 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
|
|||
QList<Message> read_msgs, important_msgs;
|
||||
|
||||
for (int i = 0; i < msgs.size(); i++) {
|
||||
QMutexLocker lck(&m_mutexDb);
|
||||
|
||||
Message msg_original(msgs[i]);
|
||||
Message* msg_tweaked_by_filter = &msgs[i];
|
||||
|
||||
|
@ -329,8 +327,6 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
|
|||
// So first insert articles, then update their label assignments etc.
|
||||
for (Label* lbl : qAsConst(msg_original.m_assignedLabels)) {
|
||||
if (!msg_tweaked_by_filter->m_assignedLabels.contains(lbl)) {
|
||||
QMutexLocker lck(&m_mutexDb);
|
||||
|
||||
// Label is not there anymore, it was deassigned.
|
||||
msg_tweaked_by_filter->m_deassignedLabelsByFilter << lbl;
|
||||
}
|
||||
|
@ -338,8 +334,6 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
|
|||
|
||||
for (Label* lbl : qAsConst(msg_tweaked_by_filter->m_assignedLabels)) {
|
||||
if (!msg_original.m_assignedLabels.contains(lbl)) {
|
||||
QMutexLocker lck(&m_mutexDb);
|
||||
|
||||
// Label is in new message, but is not in old message, it
|
||||
// was newly assigned.
|
||||
msg_tweaked_by_filter->m_assignedLabelsByFilter << lbl;
|
||||
|
|
|
@ -4,20 +4,22 @@
|
|||
|
||||
#include "3rd-party/boolinq/boolinq.h"
|
||||
#include "database/databasefactory.h"
|
||||
#include "database/databasequeries.h"
|
||||
#include "definitions/definitions.h"
|
||||
#include "services/abstract/labelsnode.h"
|
||||
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlError>
|
||||
#include <QSqlQuery>
|
||||
|
||||
MessageObject::MessageObject(QSqlDatabase* db,
|
||||
const QString& feed_custom_id,
|
||||
int account_id,
|
||||
const QList<Label*>& available_labels,
|
||||
bool is_new_message,
|
||||
QObject* parent)
|
||||
: QObject(parent), m_db(db), m_feedCustomId(feed_custom_id), m_accountId(account_id), m_message(nullptr),
|
||||
m_availableLabels(available_labels), m_runningAfterFetching(is_new_message) {}
|
||||
MessageObject::MessageObject(QSqlDatabase* db, Feed* feed, ServiceRoot* account, bool is_new_message, QObject* parent)
|
||||
: QObject(parent), m_db(db), m_feed(feed), m_account(account), m_message(nullptr),
|
||||
m_runningAfterFetching(is_new_message) {
|
||||
|
||||
m_feedCustomId = m_feed != nullptr ? m_feed->customId() : QString::number(NO_PARENT_CATEGORY);
|
||||
m_accountId = m_account != nullptr ? m_account->accountId() : NO_PARENT_CATEGORY;
|
||||
m_availableLabels = m_account != nullptr ? m_account->labelsNode()->labels() : QList<Label*>();
|
||||
}
|
||||
|
||||
void MessageObject::setMessage(Message* message) {
|
||||
m_message = message;
|
||||
|
@ -159,6 +161,19 @@ QString MessageObject::findLabelId(const QString& label_title) const {
|
|||
return found_lbl != nullptr ? found_lbl->customId() : QString();
|
||||
}
|
||||
|
||||
QString MessageObject::createLabelId(const QString& title, const QString& hex_color) const {
|
||||
QString lbl_id = findLabelId(title);
|
||||
|
||||
if (!lbl_id.isEmpty()) {
|
||||
// Label exists.
|
||||
return lbl_id;
|
||||
}
|
||||
|
||||
if (hex_color.isEmpty()) {
|
||||
// Generate color.
|
||||
}
|
||||
}
|
||||
|
||||
void MessageObject::addEnclosure(const QString& url, const QString& mime_type) const {
|
||||
m_message->m_enclosures.append(Enclosure(url, mime_type));
|
||||
}
|
||||
|
|
|
@ -68,9 +68,8 @@ class MessageObject : public QObject {
|
|||
Q_ENUM(DuplicateCheck)
|
||||
|
||||
explicit MessageObject(QSqlDatabase* db,
|
||||
const QString& feed_custom_id,
|
||||
int account_id,
|
||||
const QList<Label*>& available_labels,
|
||||
Feed* feed,
|
||||
ServiceRoot* account,
|
||||
bool is_new_message,
|
||||
QObject* parent = nullptr);
|
||||
|
||||
|
@ -92,6 +91,10 @@ class MessageObject : public QObject {
|
|||
// Returns label custom ID given label title.
|
||||
Q_INVOKABLE QString findLabelId(const QString& label_title) const;
|
||||
|
||||
// Returns label custom ID given label title or creates
|
||||
// the label if it does not exist.
|
||||
Q_INVOKABLE QString createLabelId(const QString& title, const QString& hex_color = {}) const;
|
||||
|
||||
// Add multimedia attachment to the message.
|
||||
Q_INVOKABLE void addEnclosure(const QString& url, const QString& mime_type) const;
|
||||
|
||||
|
@ -146,6 +149,10 @@ class MessageObject : public QObject {
|
|||
|
||||
private:
|
||||
QSqlDatabase* m_db;
|
||||
|
||||
Feed* m_feed;
|
||||
ServiceRoot* m_account;
|
||||
|
||||
QString m_feedCustomId;
|
||||
int m_accountId;
|
||||
Message* m_message;
|
||||
|
|
|
@ -280,10 +280,8 @@ void FormMessageFiltersManager::testFilter() {
|
|||
QJSEngine filter_engine;
|
||||
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
|
||||
MessageObject msg_obj(&database,
|
||||
selected_fd_cat->kind() == RootItem::Kind::Feed ? selected_fd_cat->customId()
|
||||
: QString::number(NO_PARENT_CATEGORY),
|
||||
selectedAccount() != nullptr ? selectedAccount()->accountId() : NO_PARENT_CATEGORY,
|
||||
selected_fd_cat->getParentServiceRoot()->labelsNode()->labels(),
|
||||
selected_fd_cat->kind() == RootItem::Kind::Feed ? selected_fd_cat->toFeed() : nullptr,
|
||||
selectedAccount(),
|
||||
false);
|
||||
auto* fltr = selectedFilter();
|
||||
|
||||
|
@ -362,11 +360,7 @@ void FormMessageFiltersManager::processCheckedFeeds() {
|
|||
for (RootItem* it : checked) {
|
||||
if (it->kind() == RootItem::Kind::Feed) {
|
||||
QJSEngine filter_engine;
|
||||
MessageObject msg_obj(&database,
|
||||
it->customId(),
|
||||
selectedAccount()->accountId(),
|
||||
it->getParentServiceRoot()->labelsNode()->labels(),
|
||||
false);
|
||||
MessageObject msg_obj(&database, it->toFeed(), selectedAccount(), false);
|
||||
|
||||
MessageFilter::initializeFilteringEngine(filter_engine, &msg_obj);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue