diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-05-09 12:02:30 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-07-12 11:54:29 +0200 |
commit | 9a65bde0fa438ee4ad101b58721b77182ae1ae70 (patch) | |
tree | 5d3dd323f812e370af8a2cc5260ff523d7024f7e /lib | |
parent | 44aeb57e196bcd9e041c498a212f17b0dcd1244f (diff) | |
download | libquotient-9a65bde0fa438ee4ad101b58721b77182ae1ae70.tar.gz libquotient-9a65bde0fa438ee4ad101b58721b77182ae1ae70.zip |
Make AliasesEventContent a simple structure
JSON conversions are moved out of the class, obviating the need to
define the plain data constructor and gaining default-constructibility
along the way - previously the default constructor was preempted
by user-defined ones.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/events/roomcanonicalaliasevent.h | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h index bb8654e5..e599699d 100644 --- a/lib/events/roomcanonicalaliasevent.h +++ b/lib/events/roomcanonicalaliasevent.h @@ -7,35 +7,30 @@ #include "stateevent.h" namespace Quotient { -namespace EventContent{ - class AliasesEventContent { - - public: - - template<typename T1, typename T2> - AliasesEventContent(T1&& canonicalAlias, T2&& altAliases) - : canonicalAlias(std::forward<T1>(canonicalAlias)) - , altAliases(std::forward<T2>(altAliases)) - { } - - AliasesEventContent(const QJsonObject& json) - : canonicalAlias(fromJson<QString>(json["alias"])) - , altAliases(fromJson<QStringList>(json["alt_aliases"])) - { } - - auto toJson() const - { - QJsonObject jo; - addParam<IfNotEmpty>(jo, QStringLiteral("alias"), canonicalAlias); - addParam<IfNotEmpty>(jo, QStringLiteral("alt_aliases"), altAliases); - return jo; - } - +namespace EventContent { + struct AliasesEventContent { QString canonicalAlias; QStringList altAliases; }; } // namespace EventContent +template<> +inline EventContent::AliasesEventContent fromJson(const QJsonObject& jo) +{ + return EventContent::AliasesEventContent { + fromJson<QString>(jo["alias"_ls]), + fromJson<QStringList>(jo["alt_aliases"_ls]) + }; +} +template<> +inline auto toJson(const EventContent::AliasesEventContent& c) +{ + QJsonObject jo; + addParam<IfNotEmpty>(jo, QStringLiteral("alias"), c.canonicalAlias); + addParam<IfNotEmpty>(jo, QStringLiteral("alt_aliases"), c.altAliases); + return jo; +} + class RoomCanonicalAliasEvent : public StateEvent<EventContent::AliasesEventContent> { public: |