diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-09-11 13:05:40 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-09-11 13:05:40 +0200 |
commit | 6597866ead7a3eb03cfcbbd99b547de1bb72867e (patch) | |
tree | be13b1876e5bbd04ae32cf85d4b063c2f628e009 /lib/mxcreply.cpp | |
parent | 4babd9b2f1ba1d8c8c58c2f728cc4875ecf144c7 (diff) | |
download | libquotient-6597866ead7a3eb03cfcbbd99b547de1bb72867e.tar.gz libquotient-6597866ead7a3eb03cfcbbd99b547de1bb72867e.zip |
Further tweaks to MxcReply
- QNetworkReply::isSequential() already returns `true`, there's no need
to overload it again.
- Use `Q_SLOTS` instead of `slots` because it's an external library
interface and clients may use other libraries using `slots` identifier;
- Use `emit` instead of `Q_EMIT` because this is a part of internal
implementation and if we ever use a library that has an `emit`
identifier, a massive search-replace will be in order anyway.
- Use `QMetaObject::invokeMethod()` with a queued connection as
a clearer way to achieve the same goal as `QTimer::singleShot(0, ...)`.
Diffstat (limited to 'lib/mxcreply.cpp')
-rw-r--r-- | lib/mxcreply.cpp | 37 |
1 files changed, 17 insertions, 20 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 +} |