From 898dbdb5511005767724a9bfb4cff1351c8103ac Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 14 Mar 2022 06:39:22 +0100 Subject: [PATCH] docs upd --- resources/docs/Documentation.md | 9 +++++---- src/librssguard/core/messageobject.cpp | 18 +++++++++--------- src/librssguard/core/messageobject.h | 24 +++++++++++------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/resources/docs/Documentation.md b/resources/docs/Documentation.md index e78e9e3af..6275bc2ff 100644 --- a/resources/docs/Documentation.md +++ b/resources/docs/Documentation.md @@ -108,11 +108,12 @@ Also, there is a special variable named `utils`. This variable is of type `Filte RSS Guard allows to use the list of labels assigned to each article. You can, therefore, execute actions in your filtering script, based on which labels are assigned to the article. The property is called `assignedLabels` and is array of [`Label`](#Label-class) objects. Passed article also offers special function: + ```js -Boolean MessageObject.isAlreadyInDatabase(DuplicationAttributeCheck) +Boolean MessageObject.isAlreadyInDatabase(DuplicateCheck) ``` -which allows you to perform runtime check for existence of the article in RSS Guard's database. The parameter is value from enumeration [`DuplicationAttributeCheck`](#DuplicationAttributeCheck-enum) and specifies how exactly you want to match your article. +which allows you to perform runtime check for existence of the article in RSS Guard's database. The parameter is value from enumeration [`DuplicateCheck`](#duplicatecheck-enum) and specifies how exactly you want to match your article. For example, if you want to check if there is already another article with same author in database, you should call `msg.isAlreadyInDatabase(MessageObject.SameAuthor)`. Values of the enumeration can be combined via bitwise OR (`|`) operator in single call, like this: `msg.isAlreadyInDatabase(MessageObject.SameAuthor | MessageObject.SameUrl)`. @@ -137,7 +138,7 @@ Here is the reference of methods and properties of types available in your filte | Property | `isRead` | `Boolean` | | ✅ | Is message read? | Property | `isImportant` | `Boolean` | | ✅ | Is message important? | Property | `isDeleted` | `Boolean` | | | Is message placed in recycle bin? -| Method | `isAlreadyInDatabase(DuplicationAttributeCheck)` | `Boolean` | | | Allows you to test if this particular message is already stored in RSS Guard's DB. +| Method | `isAlreadyInDatabase(DuplicateCheck)` | `Boolean` | | | Allows you to test if this particular message is already stored in RSS Guard's DB. | Method | `assignLabel(String)` | `Boolean` | | | Assigns label to this message. The passed `String` value is the `customId` property of `Label` type. See its API reference for relevant info. | Method | `deassignLabel(String)` | `Boolean` | | | Removes label from this message. The passed `String` value is the `customId` property of `Label` type. See its API reference for relevant info. | Property | `runningFilterWhenFetching` | `Boolean` | ✅ | | 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. @@ -158,7 +159,7 @@ Here is the reference of methods and properties of types available in your filte Note that `MessageObject` attributes are synchronized with service even if you return `Purge` or `Ignore`. In other words, even if your filter ignores the article, you can still tweak its properties which will be synchronized back to your server. -#### `DuplicationAttributeCheck` enum +#### `DuplicateCheck` enum | Enumerant name | Integer value | Description | :--- | :--- | --- | `SameTitle` | 1 | Check if message has same title as some another messages. diff --git a/src/librssguard/core/messageobject.cpp b/src/librssguard/core/messageobject.cpp index 6097aad10..2fd4d028e 100644 --- a/src/librssguard/core/messageobject.cpp +++ b/src/librssguard/core/messageobject.cpp @@ -18,42 +18,42 @@ void MessageObject::setMessage(Message* message) { m_message = message; } -bool MessageObject::isAlreadyInDatabase(DuplicationAttributeCheck attribute_check) const { +bool MessageObject::isAlreadyInDatabase(DuplicateCheck attribute_check) const { return isDuplicateWithAttribute(attribute_check); } -bool MessageObject::isDuplicate(DuplicationAttributeCheck attribute_check) const { +bool MessageObject::isDuplicate(DuplicateCheck attribute_check) const { return isDuplicateWithAttribute(attribute_check); } -bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicationAttributeCheck attribute_check) const { +bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicateCheck attribute_check) const { // Check database according to duplication attribute_check. QSqlQuery q(*m_db); QStringList where_clauses; QVector> bind_values; // Now we construct the query according to parameter. - if ((attribute_check& DuplicationAttributeCheck::SameTitle) == DuplicationAttributeCheck::SameTitle) { + if ((attribute_check& DuplicateCheck::SameTitle) == DuplicateCheck::SameTitle) { where_clauses.append(QSL("title = :title")); bind_values.append({ QSL(":title"), title() }); } - if ((attribute_check& DuplicationAttributeCheck::SameUrl) == DuplicationAttributeCheck::SameUrl) { + if ((attribute_check& DuplicateCheck::SameUrl) == DuplicateCheck::SameUrl) { where_clauses.append(QSL("url = :url")); bind_values.append({ QSL(":url"), url() }); } - if ((attribute_check& DuplicationAttributeCheck::SameAuthor) == DuplicationAttributeCheck::SameAuthor) { + if ((attribute_check& DuplicateCheck::SameAuthor) == DuplicateCheck::SameAuthor) { where_clauses.append(QSL("author = :author")); bind_values.append({ QSL(":author"), author() }); } - if ((attribute_check& DuplicationAttributeCheck::SameDateCreated) == DuplicationAttributeCheck::SameDateCreated) { + if ((attribute_check& DuplicateCheck::SameDateCreated) == DuplicateCheck::SameDateCreated) { where_clauses.append(QSL("date_created = :date_created")); bind_values.append({ QSL(":date_created"), created().toMSecsSinceEpoch() }); } - if ((attribute_check& DuplicationAttributeCheck::SameCustomId) == DuplicationAttributeCheck::SameCustomId) { + if ((attribute_check& DuplicateCheck::SameCustomId) == DuplicateCheck::SameCustomId) { where_clauses.append(QSL("custom_id = :custom_id")); bind_values.append({ QSL(":custom_id"), customId() }); } @@ -61,7 +61,7 @@ bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicationAttribute where_clauses.append(QSL("account_id = :account_id")); bind_values.append({ QSL(":account_id"), accountId() }); - if ((attribute_check& DuplicationAttributeCheck::AllFeedsSameAccount) != DuplicationAttributeCheck::AllFeedsSameAccount) { + if ((attribute_check& DuplicateCheck::AllFeedsSameAccount) != DuplicateCheck::AllFeedsSameAccount) { // Limit to current feed. where_clauses.append(QSL("feed = :feed")); bind_values.append({ QSL(":feed"), feedCustomId() }); diff --git a/src/librssguard/core/messageobject.h b/src/librssguard/core/messageobject.h index 9262c4cd3..45d4b3b91 100644 --- a/src/librssguard/core/messageobject.h +++ b/src/librssguard/core/messageobject.h @@ -43,7 +43,7 @@ class MessageObject : public QObject { Q_ENUM(FilteringAction) - enum class DuplicationAttributeCheck { + enum class DuplicateCheck { // Message with same title in DB. SameTitle = 1, @@ -65,7 +65,7 @@ class MessageObject : public QObject { SameCustomId = 32 }; - Q_ENUM(DuplicationAttributeCheck) + Q_ENUM(DuplicateCheck) explicit MessageObject(QSqlDatabase* db, const QString& feed_custom_id, @@ -77,11 +77,9 @@ class MessageObject : public QObject { void setMessage(Message* message); // Check if message is duplicate with another messages in DB. - // Parameter "attribute_check" is DuplicationAttributeCheck enum - // value casted to int. - Q_INVOKABLE bool isAlreadyInDatabase(MessageObject::DuplicationAttributeCheck attribute_check) const; - Q_INVOKABLE bool isDuplicate(MessageObject::DuplicationAttributeCheck attribute_check) const; - Q_INVOKABLE bool isDuplicateWithAttribute(MessageObject::DuplicationAttributeCheck attribute_check) const; + Q_INVOKABLE bool isAlreadyInDatabase(MessageObject::DuplicateCheck attribute_check) const; + Q_INVOKABLE bool isDuplicate(MessageObject::DuplicateCheck attribute_check) const; + Q_INVOKABLE bool isDuplicateWithAttribute(MessageObject::DuplicateCheck attribute_check) const; // Adds given label to list of assigned labels to this message. // Returns true if label was assigned now or if the message already has it assigned. @@ -148,14 +146,14 @@ class MessageObject : public QObject { bool m_runningAfterFetching; }; -inline MessageObject::DuplicationAttributeCheck operator|(MessageObject::DuplicationAttributeCheck lhs, - MessageObject::DuplicationAttributeCheck rhs) { - return static_cast(int(lhs) | int(rhs)); +inline MessageObject::DuplicateCheck operator|(MessageObject::DuplicateCheck lhs, + MessageObject::DuplicateCheck rhs) { + return static_cast(int(lhs) | int(rhs)); } -inline MessageObject::DuplicationAttributeCheck operator&(MessageObject::DuplicationAttributeCheck lhs, - MessageObject::DuplicationAttributeCheck rhs) { - return static_cast(int(lhs) & int(rhs)); +inline MessageObject::DuplicateCheck operator&(MessageObject::DuplicateCheck lhs, + MessageObject::DuplicateCheck rhs) { + return static_cast(int(lhs) & int(rhs)); } #endif // MESSAGEOBJECT_H