aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/encryptedevent.cpp10
-rw-r--r--lib/events/event.h4
-rw-r--r--lib/events/roomevent.cpp6
-rw-r--r--lib/events/stateevent.cpp2
4 files changed, 12 insertions, 10 deletions
diff --git a/lib/events/encryptedevent.cpp b/lib/events/encryptedevent.cpp
index c97ccc16..ec00ad4c 100644
--- a/lib/events/encryptedevent.cpp
+++ b/lib/events/encryptedevent.cpp
@@ -49,14 +49,16 @@ RoomEventPtr EncryptedEvent::createDecrypted(const QString &decrypted) const
eventObject["event_id"] = id();
eventObject["sender"] = senderId();
eventObject["origin_server_ts"] = originTimestamp().toMSecsSinceEpoch();
- if (const auto relatesToJson = contentPart("m.relates_to"_ls); !relatesToJson.isUndefined()) {
+ if (const auto relatesToJson = contentPart<QJsonObject>("m.relates_to"_ls);
+ !relatesToJson.isEmpty()) {
auto content = eventObject["content"].toObject();
- content["m.relates_to"] = relatesToJson.toObject();
+ content["m.relates_to"] = relatesToJson;
eventObject["content"] = content;
}
- if (const auto redactsJson = unsignedPart("redacts"_ls); !redactsJson.isUndefined()) {
+ if (const auto redactsJson = unsignedPart<QString>("redacts"_ls);
+ !redactsJson.isEmpty()) {
auto unsign = eventObject["unsigned"].toObject();
- unsign["redacts"] = redactsJson.toString();
+ unsign["redacts"] = redactsJson;
eventObject["unsigned"] = unsign;
}
return loadEvent<RoomEvent>(eventObject);
diff --git a/lib/events/event.h b/lib/events/event.h
index 05eb51e9..da6cf3c7 100644
--- a/lib/events/event.h
+++ b/lib/events/event.h
@@ -212,7 +212,7 @@ public:
const QJsonObject contentJson() const;
- template <typename T = QJsonValue, typename KeyT>
+ template <typename T, typename KeyT>
const T contentPart(KeyT&& key) const
{
return fromJson<T>(contentJson()[std::forward<KeyT>(key)]);
@@ -227,7 +227,7 @@ public:
const QJsonObject unsignedJson() const;
- template <typename T = QJsonValue, typename KeyT>
+ template <typename T, typename KeyT>
const T unsignedPart(KeyT&& key) const
{
return fromJson<T>(unsignedJson()[std::forward<KeyT>(key)]);
diff --git a/lib/events/roomevent.cpp b/lib/events/roomevent.cpp
index 3ddf5ac4..e695e0ec 100644
--- a/lib/events/roomevent.cpp
+++ b/lib/events/roomevent.cpp
@@ -15,9 +15,9 @@ RoomEvent::RoomEvent(Type type, event_mtype_t matrixType,
RoomEvent::RoomEvent(Type type, const QJsonObject& json) : Event(type, json)
{
- if (const auto redaction = unsignedPart(RedactedCauseKeyL);
- redaction.isObject())
- _redactedBecause = makeEvent<RedactionEvent>(redaction.toObject());
+ if (const auto redaction = unsignedPart<QJsonObject>(RedactedCauseKeyL);
+ !redaction.isEmpty())
+ _redactedBecause = makeEvent<RedactionEvent>(redaction);
}
RoomEvent::~RoomEvent() = default; // Let the smart pointer do its job
diff --git a/lib/events/stateevent.cpp b/lib/events/stateevent.cpp
index c343e37f..43dfd6e8 100644
--- a/lib/events/stateevent.cpp
+++ b/lib/events/stateevent.cpp
@@ -21,7 +21,7 @@ StateEventBase::StateEventBase(Event::Type type, event_mtype_t matrixType,
bool StateEventBase::repeatsState() const
{
- const auto prevContentJson = unsignedPart(PrevContentKeyL);
+ const auto prevContentJson = unsignedPart<QJsonObject>(PrevContentKeyL);
return fullJson().value(ContentKeyL) == prevContentJson;
}