Inoreader plugin now fetches labels assigned to messages as well.
This commit is contained in:
parent
72ab1a43b0
commit
4a0542529b
@ -509,7 +509,7 @@ bool ServiceRoot::loadMessagesForItem(RootItem* item, MessagesModel* model) {
|
||||
else if (item->kind() == RootItem::Kind::Label) {
|
||||
// Show messages with particular label.
|
||||
model->setFilter(QString("Messages.is_deleted = 0 AND Messages.is_pdeleted = 0 AND Messages.account_id = %1 AND "
|
||||
"(SELECT COUNT(*) FROM LabelsInMessages WHERE account_id = %1 AND message = Messages.custom_id AND label = %2) > 0")
|
||||
"(SELECT COUNT(*) FROM LabelsInMessages WHERE account_id = %1 AND message = Messages.custom_id AND label = '%2') > 0")
|
||||
.arg(QString::number(accountId()), item->customId()));
|
||||
}
|
||||
else if (item->kind() == RootItem::Kind::Labels) {
|
||||
@ -534,7 +534,8 @@ bool ServiceRoot::loadMessagesForItem(RootItem* item, MessagesModel* model) {
|
||||
|
||||
QString urls = textualFeedUrls(children).join(QSL(", "));
|
||||
|
||||
qDebug("Displaying messages from feeds IDs: %s and URLs: %s.", qPrintable(filter_clause), qPrintable(urls));
|
||||
qDebugNN << "Displaying messages from feeds IDs:" << QUOTE_W_SPACE(filter_clause)
|
||||
<< "and URLs:" << QUOTE_W_SPACE_DOT(urls);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -17,7 +17,7 @@ InoreaderServiceRoot* InoreaderFeed::serviceRoot() const {
|
||||
|
||||
QList<Message> InoreaderFeed::obtainNewMessages(bool* error_during_obtaining) {
|
||||
Feed::Status error = Feed::Status::Normal;
|
||||
QList<Message> messages = serviceRoot()->network()->messages(customId(), error);
|
||||
QList<Message> messages = serviceRoot()->network()->messages(getParentServiceRoot(), customId(), error);
|
||||
|
||||
setStatus(error);
|
||||
|
||||
|
@ -132,7 +132,7 @@ QString InoreaderServiceRoot::additionalTooltip() const {
|
||||
RootItem* InoreaderServiceRoot::obtainNewTreeForSyncIn() const {
|
||||
auto tree = m_network->feedsCategories(true);
|
||||
|
||||
if (tree->childCount() > 1) {
|
||||
if (tree != nullptr && tree->childCount() > 1) {
|
||||
auto* lblroot = new LabelsNode(tree);
|
||||
auto labels = m_network->getLabels();
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "services/inoreader/network/inoreadernetworkfactory.h"
|
||||
|
||||
#include "3rd-party/boolinq/boolinq.h"
|
||||
#include "definitions/definitions.h"
|
||||
#include "gui/dialogs/formmain.h"
|
||||
#include "gui/tabwidget.h"
|
||||
@ -12,6 +13,7 @@
|
||||
#include "network-web/silentnetworkaccessmanager.h"
|
||||
#include "network-web/webfactory.h"
|
||||
#include "services/abstract/category.h"
|
||||
#include "services/abstract/labelsnode.h"
|
||||
#include "services/inoreader/definitions.h"
|
||||
#include "services/inoreader/inoreaderfeed.h"
|
||||
#include "services/inoreader/inoreaderserviceroot.h"
|
||||
@ -152,7 +154,7 @@ QList<RootItem*> InoreaderNetworkFactory::getLabels() {
|
||||
return lbls;
|
||||
}
|
||||
|
||||
QList<Message> InoreaderNetworkFactory::messages(const QString& stream_id, Feed::Status& error) {
|
||||
QList<Message> InoreaderNetworkFactory::messages(ServiceRoot* root, const QString& stream_id, Feed::Status& error) {
|
||||
Downloader downloader;
|
||||
QEventLoop loop;
|
||||
QString target_url = INOREADER_API_FEED_CONTENTS;
|
||||
@ -188,7 +190,7 @@ QList<Message> InoreaderNetworkFactory::messages(const QString& stream_id, Feed:
|
||||
QString messages_data = downloader.lastOutputData();
|
||||
|
||||
error = Feed::Status::Normal;
|
||||
return decodeMessages(messages_data, stream_id);
|
||||
return decodeMessages(root, messages_data, stream_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -353,9 +355,10 @@ void InoreaderNetworkFactory::onAuthFailed() {
|
||||
});
|
||||
}
|
||||
|
||||
QList<Message> InoreaderNetworkFactory::decodeMessages(const QString& messages_json_data, const QString& stream_id) {
|
||||
QList<Message> InoreaderNetworkFactory::decodeMessages(ServiceRoot* root, const QString& messages_json_data, const QString& stream_id) {
|
||||
QList<Message> messages;
|
||||
QJsonArray json = QJsonDocument::fromJson(messages_json_data.toUtf8()).object()["items"].toArray();
|
||||
auto active_labels = root->labelsNode() != nullptr ? root->labelsNode()->labels() : QList<Label*>();
|
||||
|
||||
messages.reserve(json.count());
|
||||
|
||||
@ -403,6 +406,16 @@ QList<Message> InoreaderNetworkFactory::decodeMessages(const QString& messages_j
|
||||
else if (category.contains(INOREADER_STATE_IMPORTANT)) {
|
||||
message.m_isImportant = category.contains(INOREADER_STATE_IMPORTANT);
|
||||
}
|
||||
else if (category.contains(QSL("label"))) {
|
||||
Label* label = boolinq::from(active_labels.begin(), active_labels.end()).firstOrDefault([category](Label* lbl) {
|
||||
return lbl->customId() == category;
|
||||
});
|
||||
|
||||
if (label != nullptr) {
|
||||
// We found live Label object for our assigned label.
|
||||
message.m_assignedLabels.append(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message.m_contents = message_obj["summary"].toObject()["content"].toString();
|
||||
|
@ -40,7 +40,7 @@ class InoreaderNetworkFactory : public QObject {
|
||||
|
||||
QList<RootItem*> getLabels();
|
||||
|
||||
QList<Message> messages(const QString& stream_id, Feed::Status& error);
|
||||
QList<Message> messages(ServiceRoot* root, const QString& stream_id, Feed::Status& error);
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async = true);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids, bool async = true);
|
||||
|
||||
@ -49,7 +49,7 @@ class InoreaderNetworkFactory : public QObject {
|
||||
void onAuthFailed();
|
||||
|
||||
private:
|
||||
QList<Message> decodeMessages(const QString& messages_json_data, const QString& stream_id);
|
||||
QList<Message> decodeMessages(ServiceRoot* root, const QString& messages_json_data, const QString& stream_id);
|
||||
RootItem* decodeFeedCategoriesData(const QString& categories, const QString& feeds, bool obtain_icons);
|
||||
|
||||
void initializeOauth();
|
||||
|
@ -676,6 +676,7 @@ TtRssGetHeadlinesResponse::~TtRssGetHeadlinesResponse() = default;
|
||||
|
||||
QList<Message> TtRssGetHeadlinesResponse::messages(ServiceRoot* root) const {
|
||||
QList<Message> messages;
|
||||
auto active_labels = root->labelsNode() != nullptr ? root->labelsNode()->labels() : QList<Label*>();
|
||||
|
||||
for (const QJsonValue& item : m_rawContent["content"].toArray()) {
|
||||
QJsonObject mapped = item.toObject();
|
||||
@ -686,8 +687,6 @@ QList<Message> TtRssGetHeadlinesResponse::messages(ServiceRoot* root) const {
|
||||
message.m_isImportant = mapped["marked"].toBool();
|
||||
message.m_contents = mapped["content"].toString();
|
||||
|
||||
auto active_labels = root->labelsNode() != nullptr ? root->labelsNode()->labels() : QList<Label*>();
|
||||
|
||||
for (const QJsonValue& lbl_val : mapped["labels"].toArray()) {
|
||||
QString lbl_custom_id = QString::number(lbl_val.toArray().at(0).toInt());
|
||||
Label* label = boolinq::from(active_labels.begin(), active_labels.end()).firstOrDefault([lbl_custom_id](Label* lbl) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user