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