aboutsummaryrefslogtreecommitdiff
path: root/lib/events/encryptedevent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events/encryptedevent.cpp')
-rw-r--r--lib/events/encryptedevent.cpp22
1 files changed, 22 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);
+}