Fix #154.
This commit is contained in:
parent
18160564ac
commit
2264298c41
resources
src
network-web
services
@ -1 +1 @@
|
||||
Subproject commit 4a01edaec7d67d3b2ae81aeea2a3c876216fbab8
|
||||
Subproject commit ae7084718c41afc01919779e58cd449e0eebd401
|
@ -1,8 +1,8 @@
|
||||
3.5.3
|
||||
—————
|
||||
|
||||
Added:
|
||||
▪
|
||||
Fixed:
|
||||
▪ Some feed files do not have URLs of messages properly sanitized. Strip "\n" and "\t" from URls. (bug #154)
|
||||
|
||||
3.5.1
|
||||
—————
|
||||
|
@ -152,7 +152,6 @@ void Downloader::finished() {
|
||||
}
|
||||
|
||||
m_lastContentType = reply->header(QNetworkRequest::ContentTypeHeader);
|
||||
|
||||
m_lastOutputError = reply->error();
|
||||
m_activeReply->deleteLater();
|
||||
m_activeReply = nullptr;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "gui/tabwidget.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/databasequeries.h"
|
||||
#include "miscellaneous/textfactory.h"
|
||||
#include "network-web/networkfactory.h"
|
||||
#include "network-web/oauth2service.h"
|
||||
#include "network-web/silentnetworkaccessmanager.h"
|
||||
@ -140,7 +141,7 @@ QList<Message> GmailNetworkFactory::messages(const QString& stream_id, Feed::Sta
|
||||
QList<Message> more_messages = decodeLiteMessages(messages_data, stream_id, next_page_token);
|
||||
|
||||
// Now, we via batch HTTP request obtain full data for each message.
|
||||
bool obtained = obtainAndDecodeFullMessages(more_messages);
|
||||
bool obtained = obtainAndDecodeFullMessages(more_messages, stream_id);
|
||||
|
||||
if (obtained) {
|
||||
messages.append(more_messages);
|
||||
@ -329,7 +330,22 @@ void GmailNetworkFactory::onAuthFailed() {
|
||||
});
|
||||
}
|
||||
|
||||
bool GmailNetworkFactory::obtainAndDecodeFullMessages(QList<Message>& lite_messages) {
|
||||
void GmailNetworkFactory::fillFullMessage(Message& msg, const QJsonObject& json, const QString& feed_id) {
|
||||
QHash<QString, QString> headers;
|
||||
|
||||
foreach (const QJsonValue& header, json["payload"].toObject()["headers"].toArray()) {
|
||||
headers.insert(header.toObject()["name"].toString(), header.toObject()["value"].toString());
|
||||
}
|
||||
|
||||
msg.m_author = headers["From"];
|
||||
msg.m_title = headers["Subject"];
|
||||
msg.m_createdFromFeed = true;
|
||||
msg.m_created = TextFactory::parseDateTime(headers["Date"]);
|
||||
|
||||
// TODO: Pokračovat.
|
||||
}
|
||||
|
||||
bool GmailNetworkFactory::obtainAndDecodeFullMessages(QList<Message>& lite_messages, const QString& feed_id) {
|
||||
QHttpMultiPart* multi = new QHttpMultiPart();
|
||||
|
||||
multi->setContentType(QHttpMultiPart::ContentType::MixedType);
|
||||
@ -360,12 +376,14 @@ bool GmailNetworkFactory::obtainAndDecodeFullMessages(QList<Message>& lite_messa
|
||||
headers.append(QPair<QByteArray, QByteArray>(QString(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(),
|
||||
bearer.toLocal8Bit()));
|
||||
|
||||
if (NetworkFactory::performNetworkOperation(GMAIL_API_BATCH,
|
||||
timeout,
|
||||
multi,
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers).first == QNetworkReply::NetworkError::NoError) {
|
||||
NetworkResult res = NetworkFactory::performNetworkOperation(GMAIL_API_BATCH,
|
||||
timeout,
|
||||
multi,
|
||||
output,
|
||||
QNetworkAccessManager::Operation::PostOperation,
|
||||
headers);
|
||||
|
||||
if (res.first == QNetworkReply::NetworkError::NoError) {
|
||||
// We parse each part of HTTP response (it contains HTTP headers and payload with msg full data).
|
||||
foreach (const HttpResponse& part, output) {
|
||||
QJsonObject msg_doc = QJsonDocument::fromJson(part.body().toUtf8()).object();
|
||||
@ -374,8 +392,11 @@ bool GmailNetworkFactory::obtainAndDecodeFullMessages(QList<Message>& lite_messa
|
||||
if (msgs.contains(msg_id)) {
|
||||
Message& msg = msgs[msg_id];
|
||||
|
||||
fillFullMessage(msg, msg_doc, feed_id);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
|
@ -47,7 +47,8 @@ class GmailNetworkFactory : public QObject {
|
||||
void onAuthFailed();
|
||||
|
||||
private:
|
||||
bool obtainAndDecodeFullMessages(QList<Message>& lite_messages);
|
||||
void fillFullMessage(Message& msg, const QJsonObject& json, const QString& feed_id);
|
||||
bool obtainAndDecodeFullMessages(QList<Message>& lite_messages, const QString& feed_id);
|
||||
QList<Message> decodeLiteMessages(const QString& messages_json_data, const QString& stream_id, QString& next_page_token);
|
||||
|
||||
//RootItem* decodeFeedCategoriesData(const QString& categories);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "exceptions/applicationexception.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QRegularExpression>
|
||||
|
||||
FeedParser::FeedParser(const QString& data) : m_xmlData(data) {
|
||||
m_xml.setContent(m_xmlData, true);
|
||||
@ -31,6 +32,8 @@ QList<Message> FeedParser::messages() {
|
||||
new_message.m_author = feed_author;
|
||||
}
|
||||
|
||||
new_message.m_url = new_message.m_url.replace(QRegularExpression("[\\t\\n]"), QString());
|
||||
|
||||
messages.append(new_message);
|
||||
}
|
||||
catch (const ApplicationException& ex) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user