aboutsummaryrefslogtreecommitdiff
path: root/lib/mxcreply.cpp
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2021-08-31 21:47:10 +0200
committerTobias Fella <fella@posteo.de>2021-09-05 22:09:17 +0200
commit4bab0f2ef2c68b478d669f90557d6bef6332e823 (patch)
tree59059f327120c318ee216c01040ee4aad8851ad0 /lib/mxcreply.cpp
parent06a8ef6ebed5962117121486059ba46dc7f6d4f9 (diff)
downloadlibquotient-4bab0f2ef2c68b478d669f90557d6bef6332e823.tar.gz
libquotient-4bab0f2ef2c68b478d669f90557d6bef6332e823.zip
Implement the mxc protocol in the NetworkAccessManager
Allows images to be loaded using the NetworkAccessManager instead of an ImageProvider
Diffstat (limited to 'lib/mxcreply.cpp')
-rw-r--r--lib/mxcreply.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/mxcreply.cpp b/lib/mxcreply.cpp
new file mode 100644
index 00000000..49ebe603
--- /dev/null
+++ b/lib/mxcreply.cpp
@@ -0,0 +1,54 @@
+// SPDX-FileCopyrightText: Tobias Fella <fella@posteo.de>
+// SPDX-License-Identifier: LGPL-2.1-or-later
+
+#include "mxcreply.h"
+
+#include <QtCore/QBuffer>
+#include "connection.h"
+#include "room.h"
+#include "networkaccessmanager.h"
+#include "events/stickerevent.h"
+
+using namespace Quotient;
+
+class MxcReply::Private
+{
+public:
+ QNetworkReply *m_reply = nullptr;
+};
+
+MxcReply::MxcReply(QNetworkReply* reply)
+{
+ reply->setParent(this);
+ d->m_reply = reply;
+ connect(d->m_reply, &QNetworkReply::finished, this, [this]() {
+ setError(d->m_reply->error(), d->m_reply->errorString());
+ Q_EMIT finished();
+ });
+}
+
+MxcReply::MxcReply(QNetworkReply* reply, Room* room, const QString &eventId)
+ : d(std::make_unique<Private>())
+{
+ reply->setParent(this);
+ d->m_reply = reply;
+ connect(d->m_reply, &QNetworkReply::finished, this, [this, eventId]() {
+ setError(d->m_reply->error(), d->m_reply->errorString());
+ Q_EMIT finished();
+ });
+}
+
+bool MxcReply::isSequential() const
+{
+ return true;
+}
+
+qint64 MxcReply::readData(char *data, qint64 maxSize)
+{
+ return d->m_reply->read(data, maxSize);
+}
+
+void MxcReply::abort()
+{
+ d->m_reply->abort();
+} \ No newline at end of file