semi-fix to allow workaround for broken label assignment

This commit is contained in:
Martin Rotter 2022-09-05 09:11:40 +02:00
parent 459826ecfb
commit f0bb361e6f
4 changed files with 26 additions and 19 deletions

View File

@ -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 | `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 | `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 | `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 | `title` | `String` | ❌ | ❌ | Title of the message.
| Property | `url` | `String` | ❌ | ❌ | URL of the message. | Property | `url` | `String` | ❌ | ❌ | URL of the message.
| Property | `author` | `String` | ❌ | ❌ | Author of the message. | Property | `author` | `String` | ❌ | ❌ | Author of the message.

View File

@ -235,12 +235,12 @@ 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++) {
Message msg_backup(msgs[i]); Message msg_original(msgs[i]);
Message* msg_orig = &msgs[i]; Message* msg_tweaked_by_filter = &msgs[i];
// Attach live message object to wrapper. // Attach live message object to wrapper.
tmr.restart(); tmr.restart();
msg_obj.setMessage(msg_orig); msg_obj.setMessage(msg_tweaked_by_filter);
qDebugNN << LOGSEC_FEEDDOWNLOADER << "Hooking message took " << tmr.nsecsElapsed() / 1000 << " microseconds."; qDebugNN << LOGSEC_FEEDDOWNLOADER << "Hooking message took " << tmr.nsecsElapsed() / 1000 << " microseconds.";
auto feed_filters = feed->messageFilters(); auto feed_filters = feed->messageFilters();
@ -291,39 +291,41 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
break; break;
} }
if (!msg_backup.m_isRead && msg_orig->m_isRead) { if (!msg_original.m_isRead && msg_tweaked_by_filter->m_isRead) {
qDebugNN << LOGSEC_FEEDDOWNLOADER << "Message with custom ID: '" << msg_backup.m_customId qDebugNN << LOGSEC_FEEDDOWNLOADER << "Message with custom ID: '" << msg_original.m_customId
<< "' was marked as read by message scripts."; << "' 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) { if (!msg_original.m_isImportant && msg_tweaked_by_filter->m_isImportant) {
qDebugNN << LOGSEC_FEEDDOWNLOADER << "Message with custom ID: '" << msg_backup.m_customId qDebugNN << LOGSEC_FEEDDOWNLOADER << "Message with custom ID: '" << msg_original.m_customId
<< "' was marked as important by message scripts."; << "' was marked as important by message scripts.";
important_msgs << *msg_orig; important_msgs << *msg_tweaked_by_filter;
} }
// Process changed labels. // Process changed labels.
for (Label* lbl : qAsConst(msg_backup.m_assignedLabels)) { for (Label* lbl : qAsConst(msg_original.m_assignedLabels)) {
if (!msg_orig->m_assignedLabels.contains(lbl)) { if (!msg_tweaked_by_filter->m_assignedLabels.contains(lbl)) {
// Label is not there anymore, it was deassigned. // 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()) 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)) { for (Label* lbl : qAsConst(msg_tweaked_by_filter->m_assignedLabels)) {
if (!msg_backup.m_assignedLabels.contains(lbl)) { if (!msg_original.m_assignedLabels.contains(lbl)) {
// 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.
lbl->assignToMessage(*msg_orig); lbl->assignToMessage(*msg_tweaked_by_filter);
qDebugNN << LOGSEC_FEEDDOWNLOADER << "It was detected that label" << QUOTE_W_SPACE(lbl->customId()) 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).";
} }
} }

View File

@ -257,6 +257,10 @@ QString MessageObject::customId() const {
return m_message->m_customId; return m_message->m_customId;
} }
void MessageObject::setCustomId(const QString& custom_id) {
m_message->m_customId = custom_id;
}
int MessageObject::id() const { int MessageObject::id() const {
return m_message->m_id; return m_message->m_id;
} }

View File

@ -15,7 +15,7 @@ class MessageObject : public QObject {
Q_PROPERTY(QString feedCustomId READ feedCustomId) Q_PROPERTY(QString feedCustomId READ feedCustomId)
Q_PROPERTY(int accountId READ accountId) Q_PROPERTY(int accountId READ accountId)
Q_PROPERTY(int id READ id) 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 title READ title WRITE setTitle)
Q_PROPERTY(QString url READ url WRITE setUrl) Q_PROPERTY(QString url READ url WRITE setUrl)
Q_PROPERTY(QString author READ author WRITE setAuthor) Q_PROPERTY(QString author READ author WRITE setAuthor)
@ -104,6 +104,7 @@ class MessageObject : public QObject {
int accountId() const; int accountId() const;
QString customId() const; QString customId() const;
void setCustomId(const QString& custom_id);
int id() const; int id() const;