diff --git a/src/librssguard/core/feeddownloader.cpp b/src/librssguard/core/feeddownloader.cpp index 7072dedf9..465385339 100644 --- a/src/librssguard/core/feeddownloader.cpp +++ b/src/librssguard/core/feeddownloader.cpp @@ -159,12 +159,11 @@ void FeedDownloader::updateOneFeed(Feed* feed) { switch (decision) { case MessageObject::FilteringAction::Accept: - // Message is normally accepted, it could be tweaked by the filter. continue; case MessageObject::FilteringAction::Ignore: - + default: // Remove the message, we do not want it. remove_msg = true; break; @@ -201,7 +200,8 @@ void FeedDownloader::updateOneFeed(Feed* feed) { // Label is not there anymore, it was deassigned. lbl->deassignFromMessage(*msg_orig); - qDebugNN << "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)."; } @@ -213,7 +213,8 @@ void FeedDownloader::updateOneFeed(Feed* feed) { // was newly assigned. lbl->assignToMessage(*msg_orig); - qDebugNN << "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)."; } diff --git a/src/librssguard/gui/messagepreviewer.cpp b/src/librssguard/gui/messagepreviewer.cpp index 3e03fc1f2..31e03c771 100755 --- a/src/librssguard/gui/messagepreviewer.cpp +++ b/src/librssguard/gui/messagepreviewer.cpp @@ -58,10 +58,12 @@ MessagePreviewer::MessagePreviewer(bool should_resize_to_fit, QWidget* parent) m_txtMessage = new MessageBrowser(should_resize_to_fit, this); #endif + m_toolBar->setOrientation(Qt::Orientation::Vertical); + // NOTE: To make sure that if we have many labels and short message + // that whole toolbar is visible. m_toolBar->setSizePolicy(m_toolBar->sizePolicy().horizontalPolicy(), QSizePolicy::Policy::MinimumExpanding); - m_toolBar->setOrientation(Qt::Orientation::Vertical); m_layout->setContentsMargins(3, 3, 3, 3); m_layout->addWidget(m_txtMessage, 0, 1, 1, 1); m_layout->addWidget(m_toolBar, 0, 0, -1, 1); @@ -210,7 +212,7 @@ void MessagePreviewer::updateLabels(bool only_clear) { return; } - if (m_root.data() != nullptr && m_root.data()->getParentServiceRoot()->labelsNode()->labels().size() > 0) { + if (m_root.data() != nullptr && !m_root.data()->getParentServiceRoot()->labelsNode()->labels().isEmpty()) { m_separator = m_toolBar->addSeparator(); QSqlDatabase database = qApp->database()->connection(metaObject()->className()); diff --git a/src/librssguard/miscellaneous/databasequeries.cpp b/src/librssguard/miscellaneous/databasequeries.cpp index d44beb68a..c6cd15064 100755 --- a/src/librssguard/miscellaneous/databasequeries.cpp +++ b/src/librssguard/miscellaneous/databasequeries.cpp @@ -2,6 +2,7 @@ #include "miscellaneous/databasequeries.h" +#include "3rd-party/boolinq/boolinq.h" #include "exceptions/applicationexception.h" #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" @@ -132,6 +133,36 @@ QList DatabaseQueries::getLabels(const QSqlDatabase& db, int account_id) return labels; } +QList DatabaseQueries::getLabelsForMessage(const QSqlDatabase& db, + const Message& msg, + const QList installed_labels) { + QList labels; + QSqlQuery q(db); + + q.setForwardOnly(true); + q.prepare("SELECT DISTINCT label FROM LabelsInMessages WHERE message = :message AND account_id = :account_id;"); + + q.bindValue(QSL(":account_id"), msg.m_accountId); + q.bindValue(QSL(":message"), msg.m_customId); + + if (q.exec()) { + auto iter = boolinq::from(installed_labels); + + while (q.next()) { + auto lbl_id = q.value(0).toString(); + Label* candidate_label = iter.firstOrDefault([&](const Label* lbl) { + return lbl->customId() == lbl_id; + }); + + if (candidate_label != nullptr) { + labels << candidate_label; + } + } + } + + return labels; +} + bool DatabaseQueries::updateLabel(const QSqlDatabase& db, Label* label) { QSqlQuery q(db); diff --git a/src/librssguard/miscellaneous/databasequeries.h b/src/librssguard/miscellaneous/databasequeries.h index 3a7b4220c..df72ccab8 100644 --- a/src/librssguard/miscellaneous/databasequeries.h +++ b/src/librssguard/miscellaneous/databasequeries.h @@ -24,6 +24,7 @@ class DatabaseQueries { static bool assignLabelToMessage(const QSqlDatabase& db, Label* label, const Message& msg); static bool setLabelsForMessage(const QSqlDatabase& db, const QList& labels, const Message& msg); static QList getLabels(const QSqlDatabase& db, int account_id); + static QList getLabelsForMessage(const QSqlDatabase& db, const Message& msg, const QList installed_labels); static bool updateLabel(const QSqlDatabase& db, Label* label); static bool deleteLabel(const QSqlDatabase& db, Label* label); static bool createLabel(const QSqlDatabase& db, Label* label, int account_id);