mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-06 04:14:22 +01:00
download all messages with greader, REALLY ALL if user wants to
This commit is contained in:
parent
3b9cdb477b
commit
465f5d254f
@ -134,48 +134,60 @@ QNetworkReply::NetworkError GreaderNetwork::markMessagesStarred(RootItem::Import
|
|||||||
|
|
||||||
QList<Message> GreaderNetwork::streamContents(ServiceRoot* root, const QString& stream_id,
|
QList<Message> GreaderNetwork::streamContents(ServiceRoot* root, const QString& stream_id,
|
||||||
Feed::Status& error, const QNetworkProxy& proxy) {
|
Feed::Status& error, const QNetworkProxy& proxy) {
|
||||||
QString full_url = generateFullUrl(Operations::StreamContents).arg(m_service == GreaderServiceRoot::Service::TheOldReader
|
QString continuation;
|
||||||
? stream_id
|
|
||||||
: QUrl::toPercentEncoding(stream_id),
|
|
||||||
QString::number(batchSize() <= 0
|
|
||||||
? 2000000
|
|
||||||
: batchSize()));
|
|
||||||
auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
|
||||||
|
|
||||||
if (!ensureLogin(proxy)) {
|
if (!ensureLogin(proxy)) {
|
||||||
error = Feed::Status::AuthError;
|
error = Feed::Status::AuthError;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadOnlyUnreadMessages()) {
|
QList<Message> msgs;
|
||||||
full_url += QSL("&xt=%1").arg(GREADER_API_FULL_STATE_READ);
|
int target_msgs_size = batchSize() <= 0 ? 2000000: batchSize();
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray output_stream;
|
do {
|
||||||
auto result_stream = NetworkFactory::performNetworkOperation(full_url,
|
QString full_url = generateFullUrl(Operations::StreamContents).arg(m_service == GreaderServiceRoot::Service::TheOldReader
|
||||||
timeout,
|
? stream_id
|
||||||
{},
|
: QUrl::toPercentEncoding(stream_id),
|
||||||
output_stream,
|
QString::number(target_msgs_size));
|
||||||
QNetworkAccessManager::Operation::GetOperation,
|
auto timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
{ authHeader() },
|
|
||||||
false,
|
|
||||||
{},
|
|
||||||
{},
|
|
||||||
proxy);
|
|
||||||
|
|
||||||
if (result_stream.first != QNetworkReply::NetworkError::NoError) {
|
if (downloadOnlyUnreadMessages()) {
|
||||||
qCriticalNN << LOGSEC_GREADER
|
full_url += QSL("&xt=%1").arg(GREADER_API_FULL_STATE_READ);
|
||||||
<< "Cannot download messages for "
|
}
|
||||||
<< QUOTE_NO_SPACE(stream_id)
|
|
||||||
<< ", network error:"
|
if (!continuation.isEmpty()) {
|
||||||
<< QUOTE_W_SPACE_DOT(result_stream.first);
|
full_url += QSL("&c=%1").arg(continuation);
|
||||||
error = Feed::Status::NetworkError;
|
}
|
||||||
return {};
|
|
||||||
}
|
QByteArray output_stream;
|
||||||
else {
|
auto result_stream = NetworkFactory::performNetworkOperation(full_url,
|
||||||
error = Feed::Status::Normal;
|
timeout,
|
||||||
return decodeStreamContents(root, output_stream, stream_id);
|
{},
|
||||||
|
output_stream,
|
||||||
|
QNetworkAccessManager::Operation::GetOperation,
|
||||||
|
{ authHeader() },
|
||||||
|
false,
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
proxy);
|
||||||
|
|
||||||
|
if (result_stream.first != QNetworkReply::NetworkError::NoError) {
|
||||||
|
qCriticalNN << LOGSEC_GREADER
|
||||||
|
<< "Cannot download messages for "
|
||||||
|
<< QUOTE_NO_SPACE(stream_id)
|
||||||
|
<< ", network error:"
|
||||||
|
<< QUOTE_W_SPACE_DOT(result_stream.first);
|
||||||
|
error = Feed::Status::NetworkError;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
msgs.append(decodeStreamContents(root, output_stream, stream_id, continuation));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
while (!continuation.isEmpty() && msgs.size() < target_msgs_size);
|
||||||
|
|
||||||
|
error = Feed::Status::Normal;
|
||||||
|
return msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
RootItem* GreaderNetwork::categoriesFeedsLabelsTree(bool obtain_icons, const QNetworkProxy& proxy) {
|
RootItem* GreaderNetwork::categoriesFeedsLabelsTree(bool obtain_icons, const QNetworkProxy& proxy) {
|
||||||
@ -539,11 +551,14 @@ QString GreaderNetwork::simplifyStreamId(const QString& stream_id) const {
|
|||||||
|
|
||||||
QList<Message> GreaderNetwork::decodeStreamContents(ServiceRoot* root,
|
QList<Message> GreaderNetwork::decodeStreamContents(ServiceRoot* root,
|
||||||
const QString& stream_json_data,
|
const QString& stream_json_data,
|
||||||
const QString& stream_id) {
|
const QString& stream_id,
|
||||||
|
QString& continuation) {
|
||||||
QList<Message> messages;
|
QList<Message> messages;
|
||||||
QJsonArray json = QJsonDocument::fromJson(stream_json_data.toUtf8()).object()["items"].toArray();
|
QJsonDocument json_doc = QJsonDocument::fromJson(stream_json_data.toUtf8());
|
||||||
|
QJsonArray json = json_doc.object()["items"].toArray();
|
||||||
auto active_labels = root->labelsNode() != nullptr ? root->labelsNode()->labels() : QList<Label*>();
|
auto active_labels = root->labelsNode() != nullptr ? root->labelsNode()->labels() : QList<Label*>();
|
||||||
|
|
||||||
|
continuation = json_doc.object()["continuation"].toString();
|
||||||
messages.reserve(json.count());
|
messages.reserve(json.count());
|
||||||
|
|
||||||
for (const QJsonValue& obj : json) {
|
for (const QJsonValue& obj : json) {
|
||||||
|
@ -78,7 +78,7 @@ class GreaderNetwork : public QObject {
|
|||||||
bool ensureLogin(const QNetworkProxy& proxy, QNetworkReply::NetworkError* output = nullptr);
|
bool ensureLogin(const QNetworkProxy& proxy, QNetworkReply::NetworkError* output = nullptr);
|
||||||
|
|
||||||
QString simplifyStreamId(const QString& stream_id) const;
|
QString simplifyStreamId(const QString& stream_id) const;
|
||||||
QList<Message> decodeStreamContents(ServiceRoot* root, const QString& stream_json_data, const QString& stream_id);
|
QList<Message> decodeStreamContents(ServiceRoot* root, const QString& stream_json_data, const QString& stream_id, QString& continuation);
|
||||||
RootItem* decodeTagsSubscriptions(const QString& categories, const QString& feeds, bool obtain_icons, const QNetworkProxy& proxy);
|
RootItem* decodeTagsSubscriptions(const QString& categories, const QString& feeds, bool obtain_icons, const QNetworkProxy& proxy);
|
||||||
QString sanitizedBaseUrl() const;
|
QString sanitizedBaseUrl() const;
|
||||||
QString generateFullUrl(Operations operation) const;
|
QString generateFullUrl(Operations operation) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user