Inoreader now supports syncing of label assignments.
This commit is contained in:
parent
4a0542529b
commit
2880a8c0f1
@ -22,6 +22,10 @@
|
||||
#define INOREADER_STATE_READ "state/com.google/read"
|
||||
#define INOREADER_STATE_IMPORTANT "state/com.google/starred"
|
||||
|
||||
#define INOREADER_FULL_STATE_READING_LIST "user/-/state/com.google/reading-list"
|
||||
#define INOREADER_FULL_STATE_READ "user/-/state/com.google/read"
|
||||
#define INOREADER_FULL_STATE_IMPORTANT "user/-/state/com.google/starred"
|
||||
|
||||
#define INOREADER_API_FEED_CONTENTS "https://www.inoreader.com/reader/api/0/stream/contents"
|
||||
#define INOREADER_API_LIST_LABELS "https://www.inoreader.com/reader/api/0/tag/list?types=1"
|
||||
#define INOREADER_API_LIST_FEEDS "https://www.inoreader.com/reader/api/0/subscription/list"
|
||||
|
@ -181,6 +181,32 @@ void InoreaderServiceRoot::saveAllCachedData(bool async) {
|
||||
network()->markMessagesStarred(key, custom_ids, 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()->editLabels(label_custom_id, true, messages, async);
|
||||
}
|
||||
}
|
||||
|
||||
QMapIterator<QString, QStringList> l(msg_cache.m_cachedLabelDeassignments);
|
||||
|
||||
// Remove label from these messages.
|
||||
while (l.hasNext()) {
|
||||
l.next();
|
||||
auto label_custom_id = l.key();
|
||||
QStringList messages = l.value();
|
||||
|
||||
if (!messages.isEmpty()) {
|
||||
network()->editLabels(label_custom_id, false, messages, async);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool InoreaderServiceRoot::canBeDeleted() const {
|
||||
|
@ -194,14 +194,14 @@ QList<Message> InoreaderNetworkFactory::messages(ServiceRoot* root, const QStrin
|
||||
}
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& custom_ids, bool async) {
|
||||
void InoreaderNetworkFactory::editLabels(const QString& state, bool assign, const QStringList& msg_custom_ids, bool async) {
|
||||
QString target_url = INOREADER_API_EDIT_TAG;
|
||||
|
||||
if (status == RootItem::ReadStatus::Read) {
|
||||
target_url += QString("?a=user/-/") + INOREADER_STATE_READ + "&";
|
||||
if (assign) {
|
||||
target_url += QString("?a=") + state + "&";
|
||||
}
|
||||
else {
|
||||
target_url += QString("?r=user/-/") + INOREADER_STATE_READ + "&";
|
||||
target_url += QString("?r=") + state + "&";
|
||||
}
|
||||
|
||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||
@ -218,7 +218,7 @@ void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, cons
|
||||
QStringList trimmed_ids;
|
||||
QRegularExpression regex_short_id(QSL("[0-9a-zA-Z]+$"));
|
||||
|
||||
for (const QString& id : custom_ids) {
|
||||
for (const QString& id : msg_custom_ids) {
|
||||
QString simplified_id = regex_short_id.match(id).captured();
|
||||
|
||||
trimmed_ids.append(QString("i=") + simplified_id);
|
||||
@ -240,7 +240,6 @@ void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, cons
|
||||
|
||||
// We send this batch.
|
||||
if (async) {
|
||||
|
||||
NetworkFactory::performAsyncNetworkOperation(batch_final_url,
|
||||
timeout,
|
||||
QByteArray(),
|
||||
@ -263,72 +262,12 @@ void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, cons
|
||||
}
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& custom_ids, bool async) {
|
||||
QString target_url = INOREADER_API_EDIT_TAG;
|
||||
void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids, bool async) {
|
||||
editLabels(INOREADER_FULL_STATE_READ, status == RootItem::ReadStatus::Read, msg_custom_ids, async);
|
||||
}
|
||||
|
||||
if (importance == RootItem::Importance::Important) {
|
||||
target_url += QString("?a=user/-/") + INOREADER_STATE_IMPORTANT + "&";
|
||||
}
|
||||
else {
|
||||
target_url += QString("?r=user/-/") + INOREADER_STATE_IMPORTANT + "&";
|
||||
}
|
||||
|
||||
QString bearer = m_oauth2->bearer().toLocal8Bit();
|
||||
|
||||
if (bearer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QPair<QByteArray, QByteArray>> headers;
|
||||
|
||||
headers.append(QPair<QByteArray, QByteArray>(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(),
|
||||
m_oauth2->bearer().toLocal8Bit()));
|
||||
|
||||
QStringList trimmed_ids;
|
||||
QRegularExpression regex_short_id(QSL("[0-9a-zA-Z]+$"));
|
||||
|
||||
for (const QString& id : custom_ids) {
|
||||
QString simplified_id = regex_short_id.match(id).captured();
|
||||
|
||||
trimmed_ids.append(QString("i=") + simplified_id);
|
||||
}
|
||||
|
||||
QStringList working_subset;
|
||||
int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||
|
||||
working_subset.reserve(trimmed_ids.size() > 200 ? 200 : trimmed_ids.size());
|
||||
|
||||
// Now, we perform messages update in batches (max 200 messages per batch).
|
||||
while (!trimmed_ids.isEmpty()) {
|
||||
// We take 200 IDs.
|
||||
for (int i = 0; i < 200 && !trimmed_ids.isEmpty(); i++) {
|
||||
working_subset.append(trimmed_ids.takeFirst());
|
||||
}
|
||||
|
||||
QString batch_final_url = target_url + working_subset.join(QL1C('&'));
|
||||
|
||||
// We send this batch.
|
||||
if (async) {
|
||||
NetworkFactory::performAsyncNetworkOperation(batch_final_url,
|
||||
timeout,
|
||||
QByteArray(),
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
headers);
|
||||
}
|
||||
else {
|
||||
QByteArray output;
|
||||
|
||||
NetworkFactory::performNetworkOperation(batch_final_url,
|
||||
timeout,
|
||||
QByteArray(),
|
||||
output,
|
||||
QNetworkAccessManager::Operation::GetOperation,
|
||||
headers);
|
||||
}
|
||||
|
||||
// Cleanup for next batch.
|
||||
working_subset.clear();
|
||||
}
|
||||
void InoreaderNetworkFactory::markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids, bool async) {
|
||||
editLabels(INOREADER_FULL_STATE_IMPORTANT, importance == RootItem::Importance::Important, msg_custom_ids, async);
|
||||
}
|
||||
|
||||
void InoreaderNetworkFactory::onTokensError(const QString& error, const QString& error_description) {
|
||||
|
@ -41,8 +41,11 @@ class InoreaderNetworkFactory : public QObject {
|
||||
QList<RootItem*> getLabels();
|
||||
|
||||
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);
|
||||
|
||||
void editLabels(const QString& state, bool assign, const QStringList& msg_custom_ids, bool async = true);
|
||||
|
||||
void markMessagesRead(RootItem::ReadStatus status, const QStringList& msg_custom_ids, bool async = true);
|
||||
void markMessagesStarred(RootItem::Importance importance, const QStringList& msg_custom_ids, bool async = true);
|
||||
|
||||
private slots:
|
||||
void onTokensError(const QString& error, const QString& error_description);
|
||||
|
Loading…
x
Reference in New Issue
Block a user