diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-01-04 10:30:17 +0100 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-05-08 17:43:58 +0200 |
commit | b094a75f704b59f1382b6eec1f3bf0ab51fb0a85 (patch) | |
tree | a150f3eb9d61c3192678d896809137679054c178 | |
parent | b79f67919e05698a8c3daffbe0fe53fa1ce46e54 (diff) | |
download | libquotient-b094a75f704b59f1382b6eec1f3bf0ab51fb0a85.tar.gz libquotient-b094a75f704b59f1382b6eec1f3bf0ab51fb0a85.zip |
StateEvent: use non-member JSON converters
With the reworked JsonConverter code it is possible to work uniformly
with structures that have a member toJson() and a constructor converting
from QJsonObject, as well as with structures that rely on an external
JsonConverter specialisation.
-rw-r--r-- | lib/events/eventcontent.h | 1 | ||||
-rw-r--r-- | lib/events/stateevent.h | 11 |
2 files changed, 6 insertions, 6 deletions
diff --git a/lib/events/eventcontent.h b/lib/events/eventcontent.h index de9a792b..76f20f79 100644 --- a/lib/events/eventcontent.h +++ b/lib/events/eventcontent.h @@ -34,7 +34,6 @@ namespace EventContent { explicit Base(QJsonObject o = {}) : originalJson(std::move(o)) {} virtual ~Base() = default; - // FIXME: make toJson() from converters.* work on base classes QJsonObject toJson() const; public: diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h index 88da68f8..19905431 100644 --- a/lib/events/stateevent.h +++ b/lib/events/stateevent.h @@ -72,7 +72,7 @@ struct Prev { explicit Prev(const QJsonObject& unsignedJson, ContentParamTs&&... contentParams) : senderId(unsignedJson.value("prev_sender"_ls).toString()) - , content(unsignedJson.value(PrevContentKeyL).toObject(), + , content(fromJson<ContentT>(unsignedJson.value(PrevContentKeyL)), std::forward<ContentParamTs>(contentParams)...) {} @@ -89,7 +89,8 @@ public: explicit StateEvent(Type type, const QJsonObject& fullJson, ContentParamTs&&... contentParams) : StateEventBase(type, fullJson) - , _content(contentJson(), std::forward<ContentParamTs>(contentParams)...) + , _content(fromJson<ContentT>(contentJson()), + std::forward<ContentParamTs>(contentParams)...) { const auto& unsignedData = unsignedJson(); if (unsignedData.contains(PrevContentKeyL)) @@ -101,9 +102,9 @@ public: const QString& stateKey, ContentParamTs&&... contentParams) : StateEventBase(type, matrixType, stateKey) - , _content(std::forward<ContentParamTs>(contentParams)...) + , _content{std::forward<ContentParamTs>(contentParams)...} { - editJson().insert(ContentKey, _content.toJson()); + editJson().insert(ContentKey, toJson(_content)); } const ContentT& content() const { return _content; } @@ -111,7 +112,7 @@ public: void editContent(VisitorT&& visitor) { visitor(_content); - editJson()[ContentKeyL] = _content.toJson(); + editJson()[ContentKeyL] = toJson(_content); } const ContentT* prevContent() const { |