aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/encryptedevent.cpp22
-rw-r--r--lib/events/encryptedevent.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/lib/events/encryptedevent.cpp b/lib/events/encryptedevent.cpp
index 0290f973..c9257584 100644
--- a/lib/events/encryptedevent.cpp
+++ b/lib/events/encryptedevent.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "encryptedevent.h"
+#include "roommessageevent.h"
using namespace Quotient;
@@ -30,3 +31,24 @@ EncryptedEvent::EncryptedEvent(const QJsonObject& obj)
{
qCDebug(E2EE) << "Encrypted event from" << senderId();
}
+
+RoomEventPtr EncryptedEvent::createDecrypted(const QString &decrypted) const
+{
+ auto eventObject = QJsonDocument::fromJson(decrypted.toUtf8()).object();
+ eventObject["event_id"] = id();
+ eventObject["sender"] = senderId();
+ eventObject["origin_server_ts"] = originTimestamp().toMSecsSinceEpoch();
+ if(contentJson().contains("m.relates_to")) {
+ auto relates = contentJson()["m.relates_to"].toObject();
+ auto content = eventObject["content"].toObject();
+ content["m.relates_to"] = relates;
+ eventObject["content"] = content;
+ }
+ if(unsignedJson().contains("redacts")) {
+ auto redacts = unsignedJson()["redacts"].toString();
+ auto unsign = eventObject["unsigned"].toObject();
+ unsign["redacts"] = redacts;
+ eventObject["unsigned"] = unsign;
+ }
+ return makeEvent<RoomMessageEvent>(eventObject);
+}
diff --git a/lib/events/encryptedevent.h b/lib/events/encryptedevent.h
index 1d7ea913..28398827 100644
--- a/lib/events/encryptedevent.h
+++ b/lib/events/encryptedevent.h
@@ -61,6 +61,7 @@ public:
/* device_id and session_id are required with Megolm */
QString deviceId() const { return contentPart<QString>(DeviceIdKeyL); }
QString sessionId() const { return contentPart<QString>(SessionIdKeyL); }
+ RoomEventPtr createDecrypted(const QString &decrypted) const;
};
REGISTER_EVENT_TYPE(EncryptedEvent)