From f0bb361e6f1a767a2f0f2487c8a30ed90d60033d Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 5 Sep 2022 09:11:40 +0200 Subject: [PATCH] semi-fix to allow workaround for broken label assignment --- resources/docs/Documentation.md | 2 +- src/librssguard/core/feeddownloader.cpp | 36 +++++++++++++------------ src/librssguard/core/messageobject.cpp | 4 +++ src/librssguard/core/messageobject.h | 3 ++- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/resources/docs/Documentation.md b/resources/docs/Documentation.md index b517350a4..98fb648e7 100644 --- a/resources/docs/Documentation.md +++ b/resources/docs/Documentation.md @@ -132,7 +132,7 @@ Here is the reference of methods and properties of types available in your filte | Property | `feedCustomId` | `String` | ✅ | ❌ | Service-specific ID of the feed which this message belongs to. | Property | `accountId` | `Number` | ✅ | ❌ | RSS Guard's ID of the account activated in the program. This property is highly advanced and you probably do not need to use it at all. | Property | `id` | `Number` | ✅ | ❌ | ID assigned to the message in RSS Guard local database. -| Property | `customId` | `String` | ✅ | ❌ | ID of the message as provided by the remote service or feed file. +| Property | `customId` | `String` | ❌ | ❌ | ID of the message as provided by the remote service or feed file. | Property | `title` | `String` | ❌ | ❌ | Title of the message. | Property | `url` | `String` | ❌ | ❌ | URL of the message. | Property | `author` | `String` | ❌ | ❌ | Author of the message. diff --git a/src/librssguard/core/feeddownloader.cpp b/src/librssguard/core/feeddownloader.cpp index 7dc4ed606..09d71b61c 100644 --- a/src/librssguard/core/feeddownloader.cpp +++ b/src/librssguard/core/feeddownloader.cpp @@ -235,12 +235,12 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc, QList read_msgs, important_msgs; for (int i = 0; i < msgs.size(); i++) { - Message msg_backup(msgs[i]); - Message* msg_orig = &msgs[i]; + Message msg_original(msgs[i]); + Message* msg_tweaked_by_filter = &msgs[i]; // Attach live message object to wrapper. tmr.restart(); - msg_obj.setMessage(msg_orig); + msg_obj.setMessage(msg_tweaked_by_filter); qDebugNN << LOGSEC_FEEDDOWNLOADER << "Hooking message took " << tmr.nsecsElapsed() / 1000 << " microseconds."; auto feed_filters = feed->messageFilters(); @@ -291,39 +291,41 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc, break; } - if (!msg_backup.m_isRead && msg_orig->m_isRead) { - qDebugNN << LOGSEC_FEEDDOWNLOADER << "Message with custom ID: '" << msg_backup.m_customId + if (!msg_original.m_isRead && msg_tweaked_by_filter->m_isRead) { + qDebugNN << LOGSEC_FEEDDOWNLOADER << "Message with custom ID: '" << msg_original.m_customId << "' was marked as read by message scripts."; - read_msgs << *msg_orig; + read_msgs << *msg_tweaked_by_filter; } - if (!msg_backup.m_isImportant && msg_orig->m_isImportant) { - qDebugNN << LOGSEC_FEEDDOWNLOADER << "Message with custom ID: '" << msg_backup.m_customId + if (!msg_original.m_isImportant && msg_tweaked_by_filter->m_isImportant) { + qDebugNN << LOGSEC_FEEDDOWNLOADER << "Message with custom ID: '" << msg_original.m_customId << "' was marked as important by message scripts."; - important_msgs << *msg_orig; + important_msgs << *msg_tweaked_by_filter; } // Process changed labels. - for (Label* lbl : qAsConst(msg_backup.m_assignedLabels)) { - if (!msg_orig->m_assignedLabels.contains(lbl)) { + for (Label* lbl : qAsConst(msg_original.m_assignedLabels)) { + if (!msg_tweaked_by_filter->m_assignedLabels.contains(lbl)) { // Label is not there anymore, it was deassigned. - lbl->deassignFromMessage(*msg_orig); + lbl->deassignFromMessage(*msg_tweaked_by_filter); qDebugNN << LOGSEC_FEEDDOWNLOADER << "It was detected that label" << QUOTE_W_SPACE(lbl->customId()) - << "was DEASSIGNED from message" << QUOTE_W_SPACE(msg_orig->m_customId) << "by message filter(s)."; + << "was DEASSIGNED from message" << QUOTE_W_SPACE(msg_tweaked_by_filter->m_customId) + << "by message filter(s)."; } } - for (Label* lbl : qAsConst(msg_orig->m_assignedLabels)) { - if (!msg_backup.m_assignedLabels.contains(lbl)) { + for (Label* lbl : qAsConst(msg_tweaked_by_filter->m_assignedLabels)) { + if (!msg_original.m_assignedLabels.contains(lbl)) { // Label is in new message, but is not in old message, it // was newly assigned. - lbl->assignToMessage(*msg_orig); + lbl->assignToMessage(*msg_tweaked_by_filter); qDebugNN << LOGSEC_FEEDDOWNLOADER << "It was detected that label" << QUOTE_W_SPACE(lbl->customId()) - << "was ASSIGNED to message" << QUOTE_W_SPACE(msg_orig->m_customId) << "by message filter(s)."; + << "was ASSIGNED to message" << QUOTE_W_SPACE(msg_tweaked_by_filter->m_customId) + << "by message filter(s)."; } } diff --git a/src/librssguard/core/messageobject.cpp b/src/librssguard/core/messageobject.cpp index af5574ec6..b7d8cef2b 100644 --- a/src/librssguard/core/messageobject.cpp +++ b/src/librssguard/core/messageobject.cpp @@ -257,6 +257,10 @@ QString MessageObject::customId() const { return m_message->m_customId; } +void MessageObject::setCustomId(const QString& custom_id) { + m_message->m_customId = custom_id; +} + int MessageObject::id() const { return m_message->m_id; } diff --git a/src/librssguard/core/messageobject.h b/src/librssguard/core/messageobject.h index 7977a1615..60d4a20f9 100644 --- a/src/librssguard/core/messageobject.h +++ b/src/librssguard/core/messageobject.h @@ -15,7 +15,7 @@ class MessageObject : public QObject { Q_PROPERTY(QString feedCustomId READ feedCustomId) Q_PROPERTY(int accountId READ accountId) Q_PROPERTY(int id READ id) - Q_PROPERTY(QString customId READ customId) + Q_PROPERTY(QString customId READ customId WRITE setCustomId) Q_PROPERTY(QString title READ title WRITE setTitle) Q_PROPERTY(QString url READ url WRITE setUrl) Q_PROPERTY(QString author READ author WRITE setAuthor) @@ -104,6 +104,7 @@ class MessageObject : public QObject { int accountId() const; QString customId() const; + void setCustomId(const QString& custom_id); int id() const;