From 42bca67768d6f174ecf125563ab28ef79b994e23 Mon Sep 17 00:00:00 2001 From: Ram Nad Date: Sun, 8 Mar 2020 02:43:23 +0530 Subject: fixing msc2432 --- lib/events/roomcanonicalaliasevent.h | 86 ++++++++++++++++++++++++++++++++++++ lib/events/simplestateevents.h | 2 - 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 lib/events/roomcanonicalaliasevent.h (limited to 'lib/events') diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h new file mode 100644 index 00000000..3f89f639 --- /dev/null +++ b/lib/events/roomcanonicalaliasevent.h @@ -0,0 +1,86 @@ +// Contains code for RoomCanonicalAlias Event +#pragma once + +#include "stateevent.h" + +namespace Quotient { +namespace EventContent{ + template + class SimpleDualContent { + public: + using first_value_type = T1; + using second_value_type = T2; + + template + SimpleDualContent(QString Key1Name, TT1&& value1, QString Key2Name, + TT2&& value2) + : value1(std::forward(value1)) + , value2(std::forward(value2)) + , key1(std::move(Key1Name)) + , key2(std::move(Key2Name)) + { } + + SimpleDualContent(const QJsonObject& json, QString key1Name, + QString key2Name) + : value1(fromJson(json[key1Name])) + , value2(fromJson(json[key2Name])) + , key1(std::move(key1Name)) + , key2(std::move(key2Name)) + { } + + QJsonObject toJson() const + { + return { { key1, Quotient::toJson(value1) }, + { key2, Quotient::toJson(value2) } }; + } + + public: + T1 value1; + T2 value2; + + protected: + QString key1; + QString key2; + }; +} // namespace EventContent + +class RoomCanonicalAliasEvent + : public StateEvent> { +public: + DEFINE_EVENT_TYPEID("m.room.canonical_alias", RoomCanonicalAliasEvent) + + explicit RoomCanonicalAliasEvent(const QJsonObject& obj) + : StateEvent(typeId(), obj, QStringLiteral("alias"), + QStringLiteral("alt_aliases")) + { } + + RoomCanonicalAliasEvent(const QString& server, const QString& alias, + const QStringList& alt_aliases) + : StateEvent(typeId(), matrixTypeId(), server, QStringLiteral("alias"), + alias, QStringLiteral("alt_aliases"), alt_aliases) + { } + + // For compatibility used at Room::setCanonicalAlias + explicit RoomCanonicalAliasEvent(const QString& value1) + : RoomCanonicalAliasEvent(value1, QStringList()) + { } + + // Because, MSC2432 specifies, that alt_aliases may be present + // without aliases as well + explicit RoomCanonicalAliasEvent(const QStringList& value2) + : RoomCanonicalAliasEvent(QString(), value2) + { } + + template + RoomCanonicalAliasEvent(T1&& value1, T2&& value2) + : StateEvent(typeId(), matrixTypeId(), QString(), + QStringLiteral("alias"), std::forward(value1), + QStringLiteral("alt_aliases"), std::forward(value2)) + { } + + QString alias() const { return content().value1; } + + QStringList alt_aliases() const { return content().value2; } +}; +REGISTER_EVENT_TYPE(RoomCanonicalAliasEvent) +} // namespace Quotient \ No newline at end of file diff --git a/lib/events/simplestateevents.h b/lib/events/simplestateevents.h index eb1d2f7a..cde5b0fd 100644 --- a/lib/events/simplestateevents.h +++ b/lib/events/simplestateevents.h @@ -69,8 +69,6 @@ namespace EventContent { // End of macro DEFINE_SIMPLE_STATE_EVENT(RoomNameEvent, "m.room.name", QString, name) -DEFINE_SIMPLE_STATE_EVENT(RoomCanonicalAliasEvent, "m.room.canonical_alias", - QString, alias) DEFINE_SIMPLE_STATE_EVENT(RoomTopicEvent, "m.room.topic", QString, topic) class RoomAliasesEvent -- cgit v1.2.3