mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-03 18:57:37 +01:00
cleanup lbls logic a bit
This commit is contained in:
parent
3cf0fe8763
commit
a96024aebd
@ -330,18 +330,6 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
|
||||
important_msgs << *msg_tweaked_by_filter;
|
||||
}
|
||||
|
||||
// Process changed labels.
|
||||
//
|
||||
// NOTE: We do not need to to this for
|
||||
// feeds which do not use online synchronised
|
||||
// labels, because those synchronized feeds
|
||||
// replace all labels later in the method.
|
||||
// const bool uses_online_labels =
|
||||
// (feed->getParentServiceRoot()->supportedLabelOperations() & ServiceRoot::LabelOperation::Synchronised) ==
|
||||
// ServiceRoot::LabelOperation::Synchronised;
|
||||
|
||||
// if (!uses_online_labels) {
|
||||
|
||||
// NOTE: We only remember what labels were added/removed in filters
|
||||
// and store the fact to server (of synchronized) and local DB later.
|
||||
// This is mainly because articles might not even be in DB yet.
|
||||
@ -352,7 +340,6 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
|
||||
|
||||
// Label is not there anymore, it was deassigned.
|
||||
msg_tweaked_by_filter->m_deassignedLabelsByFilter << lbl;
|
||||
msg_tweaked_by_filter->m_assignedLabels << lbl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,10 +350,8 @@ void FeedDownloader::updateOneFeed(ServiceRoot* acc,
|
||||
// Label is in new message, but is not in old message, it
|
||||
// was newly assigned.
|
||||
msg_tweaked_by_filter->m_assignedLabelsByFilter << lbl;
|
||||
msg_tweaked_by_filter->m_assignedLabels << lbl;
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
if (remove_msg) {
|
||||
msgs.removeAt(i--);
|
||||
|
@ -73,6 +73,9 @@ class RSSGUARD_DLLSPEC Message {
|
||||
// Is true if "created" date was obtained directly
|
||||
// from the feed, otherwise is false
|
||||
bool m_createdFromFeed = false;
|
||||
|
||||
// Notice if the article was actually inserted/updated into DB when feed was fetched.
|
||||
bool m_insertedUpdated = false;
|
||||
};
|
||||
|
||||
inline bool operator==(const Message& lhs, const Message& rhs) {
|
||||
|
@ -103,9 +103,12 @@ bool MessageObject::isDuplicateWithAttribute(MessageObject::DuplicateCheck attri
|
||||
}
|
||||
|
||||
bool MessageObject::assignLabel(const QString& label_custom_id) const {
|
||||
// NOTE: This is now not needed as the underlying bug was fixed in DB layer.
|
||||
/*
|
||||
if (m_message->m_id <= 0 && m_message->m_customId.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
Label* lbl = boolinq::from(m_availableLabels).firstOrDefault([label_custom_id](Label* lbl) {
|
||||
return lbl->customId() == label_custom_id;
|
||||
@ -124,9 +127,12 @@ bool MessageObject::assignLabel(const QString& label_custom_id) const {
|
||||
}
|
||||
|
||||
bool MessageObject::deassignLabel(const QString& label_custom_id) const {
|
||||
// NOTE: This is now not needed as the underlying bug was fixed in DB layer.
|
||||
/*
|
||||
if (m_message->m_id <= 0 && m_message->m_customId.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
Label* lbl = boolinq::from(m_message->m_assignedLabels).firstOrDefault([label_custom_id](Label* lbl) {
|
||||
return lbl->customId() == label_custom_id;
|
||||
|
@ -1341,6 +1341,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
|
||||
}
|
||||
|
||||
updated_messages.second++;
|
||||
message.m_insertedUpdated = true;
|
||||
}
|
||||
else if (query_update.lastError().isValid()) {
|
||||
qCriticalNN << LOGSEC_DB
|
||||
@ -1352,12 +1353,6 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
|
||||
}
|
||||
else {
|
||||
msgs_to_insert.append(&message);
|
||||
|
||||
if (!message.m_isRead) {
|
||||
updated_messages.first++;
|
||||
}
|
||||
|
||||
updated_messages.second++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1378,16 +1373,16 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
|
||||
qCriticalNN << LOGSEC_DB << "Message" << QUOTE_W_SPACE(msg->m_customId)
|
||||
<< "will not be inserted to DB because it does not meet DB constraints.";
|
||||
|
||||
// Message is not inserted to DB at last,
|
||||
// fix numbers.
|
||||
if (!msg->m_isRead) {
|
||||
updated_messages.first--;
|
||||
}
|
||||
|
||||
updated_messages.second--;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!msg->m_isRead) {
|
||||
updated_messages.first++;
|
||||
}
|
||||
|
||||
updated_messages.second++;
|
||||
msg->m_insertedUpdated = true;
|
||||
|
||||
vals.append(QSL("\n(':feed', ':title', :is_read, :is_important, :is_deleted, "
|
||||
"':url', ':author', :score, :date_created, ':contents', ':enclosures', "
|
||||
"':custom_id', ':custom_hash', :account_id)")
|
||||
@ -1446,19 +1441,34 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
|
||||
for (Message& message : messages) {
|
||||
if (!message.m_customId.isEmpty() || message.m_id > 0) {
|
||||
QMutexLocker lck(db_mutex);
|
||||
bool lbls_changed = false;
|
||||
|
||||
if (uses_online_labels) {
|
||||
// Store all labels obtained from server.
|
||||
setLabelsForMessage(db, message.m_assignedLabels, message);
|
||||
lbls_changed = true;
|
||||
}
|
||||
|
||||
// Adjust labels tweaked by filters.
|
||||
for (Label* assigned_by_filter : message.m_assignedLabelsByFilter) {
|
||||
assigned_by_filter->assignToMessage(message);
|
||||
lbls_changed = true;
|
||||
}
|
||||
|
||||
for (Label* removed_by_filter : message.m_deassignedLabelsByFilter) {
|
||||
removed_by_filter->deassignFromMessage(message);
|
||||
lbls_changed = true;
|
||||
}
|
||||
|
||||
if (lbls_changed && !message.m_insertedUpdated) {
|
||||
// This article was not inserted/updated in DB because its contents did not change
|
||||
// but its assigned labels were changed. Therefore we must count article
|
||||
// as updated.
|
||||
if (!message.m_isRead) {
|
||||
updated_messages.first++;
|
||||
}
|
||||
|
||||
updated_messages.second++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user