From 284f08ae0ad4a069a2e87e7d68ba679ba82d1f4a Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 19 Aug 2021 07:44:13 +0200 Subject: [PATCH] fix some followup stuff in article filtering --- resources/docs/Documentation.md | 6 +++--- src/librssguard/core/feeddownloader.cpp | 3 ++- src/librssguard/core/messageobject.cpp | 11 +++++------ src/librssguard/core/messageobject.h | 12 ++++++++---- .../gui/dialogs/formmessagefiltersmanager.cpp | 6 ++++-- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/resources/docs/Documentation.md b/resources/docs/Documentation.md index e1debd4ba..fe3f678f7 100755 --- a/resources/docs/Documentation.md +++ b/resources/docs/Documentation.md @@ -129,9 +129,9 @@ Here is the reference of methods and properties of some types available in your | `Boolean isImportant` | Is message important? | | `Boolean isDeleted` | Is message placed in recycle bin? | | `Boolean isDuplicateWithAttribute(DuplicationAttributeCheck)` | Allows you to test if this particular message is already stored in RSS Guard's DB. | -| `Boolean assignLabel(String)` | Assigns label to this message. The passed `String` value is the `customId` property of `Label` type. See its API reference for relevant info. Only works if either `customId` or `id` of this message is valid. | -| `Boolean deassignLabel(String)` | Removes label from this message. The passed `String` value is the `customId` property of `Label` type. See its API reference for relevant info. Only works if either `customId` or `id` of this message is valid. | -| `Boolean alreadyStoredInDb` | `READ-ONLY` Returns true if this message is already stored in DB. This function is the way to check if the filter is being run automatically for newly downloaded messages or manually for already existing messages. +| `Boolean assignLabel(String)` | Assigns label to this message. The passed `String` value is the `customId` property of `Label` type. See its API reference for relevant info. | +| `Boolean deassignLabel(String)` | Removes label from this message. The passed `String` value is the `customId` property of `Label` type. See its API reference for relevant info. | +| `Boolean runningFilterWhenFetching` | `READ-ONLY` Returns `true` if current run of the message filter is done when message is fetched. Returns `false` if message filter runs manually, for example from `Article filters` window. | #### `Label` class | Property/method | Description | diff --git a/src/librssguard/core/feeddownloader.cpp b/src/librssguard/core/feeddownloader.cpp index c5c9315c0..e93d54221 100644 --- a/src/librssguard/core/feeddownloader.cpp +++ b/src/librssguard/core/feeddownloader.cpp @@ -205,7 +205,8 @@ void FeedDownloader::updateOneFeed(Feed* feed, MessageObject msg_obj(&database, feed->customId(), feed->getParentServiceRoot()->accountId(), - feed->getParentServiceRoot()->labelsNode()->labels()); + feed->getParentServiceRoot()->labelsNode()->labels(), + true); MessageFilter::initializeFilteringEngine(filter_engine, &msg_obj); diff --git a/src/librssguard/core/messageobject.cpp b/src/librssguard/core/messageobject.cpp index 55834ecaa..ae5cefcd3 100755 --- a/src/librssguard/core/messageobject.cpp +++ b/src/librssguard/core/messageobject.cpp @@ -8,11 +8,10 @@ #include #include -MessageObject::MessageObject(QSqlDatabase* db, const QString& feed_custom_id, - int account_id, QList available_labels, - QObject* parent) +MessageObject::MessageObject(QSqlDatabase* db, const QString& feed_custom_id, int account_id, + QList 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_availableLabels(available_labels), m_runningAfterFetching(is_new_message) {} void MessageObject::setMessage(Message* message) { m_message = message; @@ -228,6 +227,6 @@ QList MessageObject::availableLabels() const { return m_availableLabels; } -bool MessageObject::alreadyStoredInDb() const { - return m_message->m_id > 0; +bool MessageObject::runningFilterWhenFetching() const { + return m_runningAfterFetching; } diff --git a/src/librssguard/core/messageobject.h b/src/librssguard/core/messageobject.h index 36ea5e543..acbffa07c 100755 --- a/src/librssguard/core/messageobject.h +++ b/src/librssguard/core/messageobject.h @@ -24,7 +24,7 @@ class MessageObject : public QObject { Q_PROPERTY(bool isRead READ isRead WRITE setIsRead) Q_PROPERTY(bool isImportant READ isImportant WRITE setIsImportant) Q_PROPERTY(bool isDeleted READ isDeleted WRITE setIsDeleted) - Q_PROPERTY(bool alreadyStoredInDb READ alreadyStoredInDb) + Q_PROPERTY(bool runningFilterWhenFetching READ runningFilterWhenFetching) public: enum class FilteringAction { @@ -61,8 +61,11 @@ class MessageObject : public QObject { Q_ENUM(DuplicationAttributeCheck) - explicit MessageObject(QSqlDatabase* db, const QString& feed_custom_id, - int account_id, QList available_labels, + explicit MessageObject(QSqlDatabase* db, + const QString& feed_custom_id, + int account_id, + QList available_labels, + bool is_new_message, QObject* parent = nullptr); void setMessage(Message* message); @@ -84,7 +87,7 @@ class MessageObject : public QObject { QList assignedLabels() const; QList availableLabels() const; - bool alreadyStoredInDb() const; + bool runningFilterWhenFetching() const; // Generic Message's properties bindings. QString feedCustomId() const; @@ -126,6 +129,7 @@ class MessageObject : public QObject { int m_accountId; Message* m_message; QList m_availableLabels; + bool m_runningAfterFetching; }; inline MessageObject::DuplicationAttributeCheck operator|(MessageObject::DuplicationAttributeCheck lhs, diff --git a/src/librssguard/gui/dialogs/formmessagefiltersmanager.cpp b/src/librssguard/gui/dialogs/formmessagefiltersmanager.cpp index c3fccb9f4..92026d619 100644 --- a/src/librssguard/gui/dialogs/formmessagefiltersmanager.cpp +++ b/src/librssguard/gui/dialogs/formmessagefiltersmanager.cpp @@ -226,7 +226,8 @@ void FormMessageFiltersManager::testFilter() { selectedAccount() != nullptr ? selectedAccount()->accountId() : NO_PARENT_CATEGORY, - selected_fd_cat->getParentServiceRoot()->labelsNode()->labels()); + selected_fd_cat->getParentServiceRoot()->labelsNode()->labels(), + false); auto* fltr = selectedFilter(); MessageFilter::initializeFilteringEngine(filter_engine, &msg_obj); @@ -304,7 +305,8 @@ void FormMessageFiltersManager::processCheckedFeeds() { MessageObject msg_obj(&database, it->customId(), selectedAccount()->accountId(), - it->getParentServiceRoot()->labelsNode()->labels()); + it->getParentServiceRoot()->labelsNode()->labels(), + false); MessageFilter::initializeFilteringEngine(filter_engine, &msg_obj);