diff options
-rw-r--r-- | lib/mxcreply.cpp | 37 | ||||
-rw-r--r-- | lib/mxcreply.h | 15 |
2 files changed, 24 insertions, 28 deletions
diff --git a/lib/mxcreply.cpp b/lib/mxcreply.cpp index 7819367e..daa4af9a 100644 --- a/lib/mxcreply.cpp +++ b/lib/mxcreply.cpp @@ -3,12 +3,7 @@ #include "mxcreply.h" -#include <QtCore/QBuffer> -#include <QtCore/QTimer> -#include "connection.h" #include "room.h" -#include "networkaccessmanager.h" -#include "events/stickerevent.h" using namespace Quotient; @@ -34,30 +29,32 @@ MxcReply::MxcReply(QNetworkReply* reply, Room* room, const QString &eventId) { reply->setParent(this); d->m_reply = reply; - connect(d->m_reply, &QNetworkReply::finished, this, [this, eventId]() { + connect(d->m_reply, &QNetworkReply::finished, this, [this, room, eventId]() { setError(d->m_reply->error(), d->m_reply->errorString()); setOpenMode(ReadOnly); - Q_EMIT finished(); + emit finished(); }); } -MxcReply::MxcReply() -{ - QTimer::singleShot(0, this, [this](){ - setError(QNetworkReply::ProtocolInvalidOperationError, QStringLiteral("Invalid Request")); - setFinished(true); #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) - Q_EMIT errorOccurred(QNetworkReply::ProtocolInvalidOperationError); +#define ERROR_SIGNAL errorOccurred #else - Q_EMIT error(QNetworkReply::ProtocolInvalidOperationError); +#define ERROR_SIGNAL error #endif - Q_EMIT finished(); - }); -} -bool MxcReply::isSequential() const +MxcReply::MxcReply() { - return true; + static const auto BadRequestPhrase = tr("Bad Request"); + QMetaObject::invokeMethod(this, [this]() { + setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 400); + setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, + BadRequestPhrase); + setError(QNetworkReply::ProtocolInvalidOperationError, + BadRequestPhrase); + setFinished(true); + emit ERROR_SIGNAL(QNetworkReply::ProtocolInvalidOperationError); + emit finished(); + }, Qt::QueuedConnection); } qint64 MxcReply::readData(char *data, qint64 maxSize) @@ -68,4 +65,4 @@ qint64 MxcReply::readData(char *data, qint64 maxSize) void MxcReply::abort() { d->m_reply->abort(); -}
\ No newline at end of file +} diff --git a/lib/mxcreply.h b/lib/mxcreply.h index ac3ac4f4..efaf01c6 100644 --- a/lib/mxcreply.h +++ b/lib/mxcreply.h @@ -8,23 +8,22 @@ namespace Quotient { class Room; -class Connection; + class MxcReply : public QNetworkReply { public: - MxcReply(QNetworkReply* reply, Room* room, const QString &eventId); - MxcReply(QNetworkReply* reply); - MxcReply(); - - bool isSequential() const override; + explicit MxcReply(); + explicit MxcReply(QNetworkReply *reply); + MxcReply(QNetworkReply* reply, Room* room, const QString& eventId); -public slots: +public Q_SLOTS: void abort() override; protected: qint64 readData(char *data, qint64 maxSize) override; + private: class Private; std::unique_ptr<Private> d; }; -}
\ No newline at end of file +} |