aboutsummaryrefslogtreecommitdiff
path: root/lib/mxcreply.cpp
diff options
context:
space:
mode:
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()