This commit is contained in:
Martin Rotter 2022-03-14 06:39:22 +01:00
parent 960b19fe9f
commit 898dbdb551
3 changed files with 25 additions and 26 deletions

View File

@ -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. 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: Passed article also offers special function:
```js ```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)`. 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 | `isRead` | `Boolean` | | ✅ | Is message read?
| Property | `isImportant` | `Boolean` | | ✅ | Is message important? | Property | `isImportant` | `Boolean` | | ✅ | Is message important?
| Property | `isDeleted` | `Boolean` | | | Is message placed in recycle bin? | 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 | `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. | 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. | 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. 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 | Enumerant name | Integer value | Description
| :--- | :--- | --- | :--- | :--- | ---
| `SameTitle` | 1 | Check if message has same title as some another messages. | `SameTitle` | 1 | Check if message has same title as some another messages.

View File

@ -18,42 +18,42 @@ void MessageObject::setMessage(Message* message) {
m_message = message; m_message = message;
} }
bool MessageObject::isAlreadyInDatabase(DuplicationAttributeCheck attribute_check) const { bool MessageObject::isAlreadyInDatabase(DuplicateCheck attribute_check) const {
return isDuplicateWithAttribute(attribute_check); return isDuplicateWithAttribute(attribute_check);
} }
bool MessageObject::isDuplicate(DuplicationAttributeCheck attribute_check) const { bool MessageObject::isDuplicate(DuplicateCheck attribute_check) const {
return isDuplicateWithAttribute(attribute_check); 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. // Check database according to duplication attribute_check.
QSqlQuery q(*m_db); QSqlQuery q(*m_db);
QStringList where_clauses; QStringList where_clauses;
QVector<QPair<QString, QVariant>> bind_values; QVector<QPair<QString, QVariant>> bind_values;
// Now we construct the query according to parameter. // 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")); where_clauses.append(QSL("title = :title"));
bind_values.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")); where_clauses.append(QSL("url = :url"));
bind_values.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")); where_clauses.append(QSL("author = :author"));
bind_values.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")); where_clauses.append(QSL("date_created = :date_created"));
bind_values.append({ QSL(":date_created"), created().toMSecsSinceEpoch() }); 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")); where_clauses.append(QSL("custom_id = :custom_id"));
bind_values.append({ QSL(":custom_id"), customId() }); bind_values.append({ QSL(":custom_id"), customId() });
} }
@ -61,7 +61,7 @@ bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicationAttribute
where_clauses.append(QSL("account_id = :account_id")); where_clauses.append(QSL("account_id = :account_id"));
bind_values.append({ QSL(":account_id"), accountId() }); 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. // Limit to current feed.
where_clauses.append(QSL("feed = :feed")); where_clauses.append(QSL("feed = :feed"));
bind_values.append({ QSL(":feed"), feedCustomId() }); bind_values.append({ QSL(":feed"), feedCustomId() });

View File

@ -43,7 +43,7 @@ class MessageObject : public QObject {
Q_ENUM(FilteringAction) Q_ENUM(FilteringAction)
enum class DuplicationAttributeCheck { enum class DuplicateCheck {
// Message with same title in DB. // Message with same title in DB.
SameTitle = 1, SameTitle = 1,
@ -65,7 +65,7 @@ class MessageObject : public QObject {
SameCustomId = 32 SameCustomId = 32
}; };
Q_ENUM(DuplicationAttributeCheck) Q_ENUM(DuplicateCheck)
explicit MessageObject(QSqlDatabase* db, explicit MessageObject(QSqlDatabase* db,
const QString& feed_custom_id, const QString& feed_custom_id,
@ -77,11 +77,9 @@ class MessageObject : public QObject {
void setMessage(Message* message); void setMessage(Message* message);
// Check if message is duplicate with another messages in DB. // Check if message is duplicate with another messages in DB.
// Parameter "attribute_check" is DuplicationAttributeCheck enum Q_INVOKABLE bool isAlreadyInDatabase(MessageObject::DuplicateCheck attribute_check) const;
// value casted to int. Q_INVOKABLE bool isDuplicate(MessageObject::DuplicateCheck attribute_check) const;
Q_INVOKABLE bool isAlreadyInDatabase(MessageObject::DuplicationAttributeCheck attribute_check) const; Q_INVOKABLE bool isDuplicateWithAttribute(MessageObject::DuplicateCheck attribute_check) const;
Q_INVOKABLE bool isDuplicate(MessageObject::DuplicationAttributeCheck attribute_check) const;
Q_INVOKABLE bool isDuplicateWithAttribute(MessageObject::DuplicationAttributeCheck attribute_check) const;
// Adds given label to list of assigned labels to this message. // 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. // 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; bool m_runningAfterFetching;
}; };
inline MessageObject::DuplicationAttributeCheck operator|(MessageObject::DuplicationAttributeCheck lhs, inline MessageObject::DuplicateCheck operator|(MessageObject::DuplicateCheck lhs,
MessageObject::DuplicationAttributeCheck rhs) { MessageObject::DuplicateCheck rhs) {
return static_cast<MessageObject::DuplicationAttributeCheck>(int(lhs) | int(rhs)); return static_cast<MessageObject::DuplicateCheck>(int(lhs) | int(rhs));
} }
inline MessageObject::DuplicationAttributeCheck operator&(MessageObject::DuplicationAttributeCheck lhs, inline MessageObject::DuplicateCheck operator&(MessageObject::DuplicateCheck lhs,
MessageObject::DuplicationAttributeCheck rhs) { MessageObject::DuplicateCheck rhs) {
return static_cast<MessageObject::DuplicationAttributeCheck>(int(lhs) & int(rhs)); return static_cast<MessageObject::DuplicateCheck>(int(lhs) & int(rhs));
} }
#endif // MESSAGEOBJECT_H #endif // MESSAGEOBJECT_H