aboutsummaryrefslogtreecommitdiff
path: root/lib/mxcreply.cpp
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2021-08-31 00:09:59 +0200
committerTobias Fella <fella@posteo.de>2021-12-01 21:56:59 +0100
commit8636c7028b45ee8de3125bcf4df40ad60ed949a0 (patch)
treea05ffdb2e0e36ef19fd6395834112c72646f7684 /lib/mxcreply.cpp
parentb35a736da2b09fe5cc0091f9fbd370d057503a54 (diff)
downloadlibquotient-8636c7028b45ee8de3125bcf4df40ad60ed949a0.tar.gz
libquotient-8636c7028b45ee8de3125bcf4df40ad60ed949a0.zip
Add mxc protocol to the networkaccessmanager
Diffstat (limited to 'lib/mxcreply.cpp')
-rw-r--r--lib/mxcreply.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/lib/mxcreply.cpp b/lib/mxcreply.cpp
index 0b6643fc..65078301 100644
--- a/lib/mxcreply.cpp
+++ b/lib/mxcreply.cpp
@@ -3,8 +3,17 @@
#include "mxcreply.h"
+#include <algorithm>
+#include <QBuffer>
+#include "accountregistry.h"
+#include "connection.h"
#include "room.h"
+#ifdef Quotient_E2EE_ENABLED
+#include "encryptionmanager.h"
+#include "events/encryptedfile.h"
+#endif
+
using namespace Quotient;
class MxcReply::Private
@@ -14,6 +23,8 @@ public:
: m_reply(r)
{}
QNetworkReply* m_reply;
+ Omittable<EncryptedFile> m_encryptedFile;
+ QIODevice* m_device = nullptr;
};
MxcReply::MxcReply(QNetworkReply* reply)
@@ -31,11 +42,32 @@ MxcReply::MxcReply(QNetworkReply* reply, Room* room, const QString &eventId)
: d(std::make_unique<Private>(reply))
{
reply->setParent(this);
- connect(d->m_reply, &QNetworkReply::finished, this, [this, room, eventId]() {
+ connect(d->m_reply, &QNetworkReply::finished, this, [this]() {
setError(d->m_reply->error(), d->m_reply->errorString());
+
+#ifdef Quotient_E2EE_ENABLED
+ if(!d->m_encryptedFile.has_value()) {
+ d->m_device = d->m_reply;
+ } else {
+ EncryptedFile file = *d->m_encryptedFile;
+ auto buffer = new QBuffer(this);
+ buffer->setData(EncryptionManager::decryptFile(d->m_reply->readAll(), &file));
+ d->m_device = buffer;
+ }
setOpenMode(ReadOnly);
emit finished();
+#else
+ d->m_device = d->m_reply;
+#endif
});
+
+#ifdef Quotient_E2EE_ENABLED
+ auto eventIt = room->findInTimeline(eventId);
+ if(eventIt != room->historyEdge()) {
+ auto event = eventIt->viewAs<RoomMessageEvent>();
+ d->m_encryptedFile = event->content()->fileInfo()->file;
+ }
+#endif
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
@@ -61,7 +93,7 @@ MxcReply::MxcReply()
qint64 MxcReply::readData(char *data, qint64 maxSize)
{
- return d->m_reply->read(data, maxSize);
+ return d->m_device->read(data, maxSize);
}
void MxcReply::abort()