Initial support for synchronizing label assignments for TT-RSS #102.
This commit is contained in:
parent
3cf7d6edea
commit
b1de49fb34
4 changed files with 64 additions and 0 deletions
|
@ -39,6 +39,10 @@ void CacheForServiceRoot::addLabelsAssignmentsToCache(const QList<Message>& ids_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto xx = m_cachedLabelAssignments.values();
|
||||||
|
auto xxx = m_cachedLabelDeassignments.values();
|
||||||
|
int a = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CacheForServiceRoot::addMessageStatesToCache(const QList<Message>& ids_of_messages, RootItem::Importance importance) {
|
void CacheForServiceRoot::addMessageStatesToCache(const QList<Message>& ids_of_messages, RootItem::Importance importance) {
|
||||||
|
|
|
@ -286,6 +286,50 @@ TtRssGetHeadlinesResponse TtRssNetworkFactory::getHeadlines(int feed_id, int lim
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TtRssResponse TtRssNetworkFactory::setArticleLabel(const QStringList& article_ids, const QString& label_custom_id, bool assign) {
|
||||||
|
QJsonObject json;
|
||||||
|
|
||||||
|
json["op"] = QSL("setArticleLabel");
|
||||||
|
json["sid"] = m_sessionId;
|
||||||
|
json["article_ids"] = article_ids.join(QSL(","));
|
||||||
|
json["label_id"] = label_custom_id.toInt();
|
||||||
|
json["assign"] = assign;
|
||||||
|
|
||||||
|
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
|
QByteArray result_raw;
|
||||||
|
QList<QPair<QByteArray, QByteArray>> headers;
|
||||||
|
|
||||||
|
headers << QPair<QByteArray, QByteArray>(HTTP_HEADERS_CONTENT_TYPE, TTRSS_CONTENT_TYPE_JSON);
|
||||||
|
headers << NetworkFactory::generateBasicAuthHeader(m_authUsername, m_authPassword);
|
||||||
|
|
||||||
|
NetworkResult network_reply = NetworkFactory::performNetworkOperation(m_fullUrl, timeout,
|
||||||
|
QJsonDocument(json).toJson(QJsonDocument::Compact),
|
||||||
|
result_raw,
|
||||||
|
QNetworkAccessManager::PostOperation,
|
||||||
|
headers);
|
||||||
|
TtRssResponse result(QString::fromUtf8(result_raw));
|
||||||
|
|
||||||
|
if (result.isNotLoggedIn()) {
|
||||||
|
// We are not logged in.
|
||||||
|
login();
|
||||||
|
json["sid"] = m_sessionId;
|
||||||
|
network_reply = NetworkFactory::performNetworkOperation(m_fullUrl, timeout, QJsonDocument(json).toJson(QJsonDocument::Compact),
|
||||||
|
result_raw,
|
||||||
|
QNetworkAccessManager::PostOperation,
|
||||||
|
headers);
|
||||||
|
result = TtRssResponse(QString::fromUtf8(result_raw));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (network_reply.first != QNetworkReply::NoError) {
|
||||||
|
qWarningNN << LOGSEC_TTRSS
|
||||||
|
<< "setArticleLabel failed with error"
|
||||||
|
<< QUOTE_W_SPACE_DOT(network_reply.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lastError = network_reply.first;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList& ids,
|
TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList& ids,
|
||||||
UpdateArticle::OperatingField field,
|
UpdateArticle::OperatingField field,
|
||||||
UpdateArticle::Mode mode, bool async) {
|
UpdateArticle::Mode mode, bool async) {
|
||||||
|
@ -298,6 +342,7 @@ TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList
|
||||||
json["article_ids"] = ids.join(QSL(","));
|
json["article_ids"] = ids.join(QSL(","));
|
||||||
json["mode"] = (int) mode;
|
json["mode"] = (int) mode;
|
||||||
json["field"] = (int) field;
|
json["field"] = (int) field;
|
||||||
|
|
||||||
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
QByteArray result_raw;
|
QByteArray result_raw;
|
||||||
QList<QPair<QByteArray, QByteArray>> headers;
|
QList<QPair<QByteArray, QByteArray>> headers;
|
||||||
|
|
|
@ -159,6 +159,8 @@ class TtRssNetworkFactory {
|
||||||
bool show_content, bool include_attachments,
|
bool show_content, bool include_attachments,
|
||||||
bool sanitize, bool unread_only);
|
bool sanitize, bool unread_only);
|
||||||
|
|
||||||
|
TtRssResponse setArticleLabel(const QStringList& article_ids, const QString& label_custom_id, bool assign);
|
||||||
|
|
||||||
TtRssUpdateArticleResponse updateArticles(const QStringList& ids, UpdateArticle::OperatingField field,
|
TtRssUpdateArticleResponse updateArticles(const QStringList& ids, UpdateArticle::OperatingField field,
|
||||||
UpdateArticle::Mode mode, bool async = true);
|
UpdateArticle::Mode mode, bool async = true);
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,19 @@ void TtRssServiceRoot::saveAllCachedData(bool async) {
|
||||||
async);
|
async);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMapIterator<QString, QStringList> k(msg_cache.m_cachedLabelAssignments);
|
||||||
|
|
||||||
|
// Assign label for these messages.
|
||||||
|
while (k.hasNext()) {
|
||||||
|
k.next();
|
||||||
|
auto label_custom_id = k.key();
|
||||||
|
QStringList messages = k.value();
|
||||||
|
|
||||||
|
if (!messages.isEmpty()) {
|
||||||
|
network()->setArticleLabel(messages, label_custom_id, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString TtRssServiceRoot::additionalTooltip() const {
|
QString TtRssServiceRoot::additionalTooltip() const {
|
||||||
|
|
Loading…
Add table
Reference in a new issue