Async msg marking.

This commit is contained in:
Martin Rotter 2017-10-05 12:30:36 +02:00
parent 25c8725029
commit bbba42540c
3 changed files with 21 additions and 7 deletions

View File

@ -146,6 +146,13 @@ QString InoreaderServiceRoot::code() const {
return InoreaderEntryPoint().code(); return InoreaderEntryPoint().code();
} }
QString InoreaderServiceRoot::additionalTooltip() const {
return tr("Authentication status: %1\n"
"Login tokens expiration: %2").arg(network()->oauth()->isFullyLoggedIn() ? tr("logged-in") : tr("NOT logged-in"),
network()->oauth()->tokensExpireIn().isValid() ?
network()->oauth()->tokensExpireIn().toString() : QSL("-"));
}
RootItem* InoreaderServiceRoot::obtainNewTreeForSyncIn() const { RootItem* InoreaderServiceRoot::obtainNewTreeForSyncIn() const {
return m_network->feedsCategories(true); return m_network->feedsCategories(true);
} }

View File

@ -45,6 +45,8 @@ class InoreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot {
void stop(); void stop();
QString code() const; QString code() const;
QString additionalTooltip() const;
RootItem* obtainNewTreeForSyncIn() const; RootItem* obtainNewTreeForSyncIn() const;
void saveAllCachedData(); void saveAllCachedData();

View File

@ -129,7 +129,7 @@ QList<Message> InoreaderNetworkFactory::messages(const QString& stream_id, Feed:
QString bearer = m_oauth2->bearer().toLocal8Bit(); QString bearer = m_oauth2->bearer().toLocal8Bit();
if (bearer.isEmpty()) { if (bearer.isEmpty()) {
error == Feed::Status::AuthError; error = Feed::Status::AuthError;
return QList<Message>(); return QList<Message>();
} }
@ -142,13 +142,13 @@ QList<Message> InoreaderNetworkFactory::messages(const QString& stream_id, Feed:
loop.exec(); loop.exec();
if (downloader.lastOutputError() != QNetworkReply::NetworkError::NoError) { if (downloader.lastOutputError() != QNetworkReply::NetworkError::NoError) {
error == Feed::Status::NetworkError; error = Feed::Status::NetworkError;
return QList<Message>(); return QList<Message>();
} }
else { else {
QString messages_data = downloader.lastOutputData(); QString messages_data = downloader.lastOutputData();
error == Feed::Status::Normal; error = Feed::Status::Normal;
return decodeMessages(messages_data, stream_id); return decodeMessages(messages_data, stream_id);
} }
} }
@ -171,8 +171,9 @@ void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, cons
return; return;
} }
downloader.appendRawHeader(QString("Authorization").toLocal8Bit(), bearer.toLocal8Bit()); QList<QPair<QByteArray, QByteArray>> headers;
connect(&downloader, &Downloader::completed, &loop, &QEventLoop::quit); headers.append(QPair<QByteArray, QByteArray>(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(),
m_oauth2->bearer().toLocal8Bit()));
QStringList trimmed_ids; QStringList trimmed_ids;
QRegularExpression regex_short_id(QSL("[0-9a-zA-Z]+$")); QRegularExpression regex_short_id(QSL("[0-9a-zA-Z]+$"));
@ -184,6 +185,7 @@ void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, cons
} }
QStringList working_subset; 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()); working_subset.reserve(trimmed_ids.size() > 200 ? 200 : trimmed_ids.size());
@ -197,8 +199,11 @@ void InoreaderNetworkFactory::markMessagesRead(RootItem::ReadStatus status, cons
QString batch_final_url = target_url + working_subset.join(QL1C('&')); QString batch_final_url = target_url + working_subset.join(QL1C('&'));
// We send this batch. // We send this batch.
downloader.manipulateData(target_url, QNetworkAccessManager::Operation::GetOperation); NetworkFactory::performAsyncNetworkOperation(batch_final_url,
loop.exec(); timeout,
QByteArray(),
QNetworkAccessManager::Operation::GetOperation,
headers);
// Cleanup for next batch. // Cleanup for next batch.
working_subset.clear(); working_subset.clear();