diff options
Diffstat (limited to 'lib/events')
-rw-r--r-- | lib/events/roomcanonicalaliasevent.h | 72 |
1 files changed, 22 insertions, 50 deletions
diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h index 78d541bc..012cac75 100644 --- a/lib/events/roomcanonicalaliasevent.h +++ b/lib/events/roomcanonicalaliasevent.h @@ -22,82 +22,54 @@ namespace Quotient { namespace EventContent{ - template <typename T1, typename T2> - class SimpleDualContent { + class AliasesEventContent { + public: - using first_value_type = T1; - using second_value_type = T2; - template <typename TT1, typename TT2> - SimpleDualContent(QString Key1Name, TT1&& value1, QString Key2Name, - TT2&& value2) - : value1(std::forward<TT1>(value1)) - , value2(std::forward<TT2>(value2)) - , key1(std::move(Key1Name)) - , key2(std::move(Key2Name)) + template<typename T1, typename T2> + AliasesEventContent(T1&& canonicalAlias, T2&& altAliases) + : canonicalAlias(std::forward<T1>(canonicalAlias)) + , altAliases(std::forward<T2>(altAliases)) { } - SimpleDualContent(const QJsonObject& json, QString key1Name, - QString key2Name) - : value1(fromJson<T1>(json[key1Name])) - , value2(fromJson<T2>(json[key2Name])) - , key1(std::move(key1Name)) - , key2(std::move(key2Name)) + AliasesEventContent(const QJsonObject& json) + : canonicalAlias(fromJson<QString>(json["alias"])) + , altAliases(fromJson<QStringList>(json["alt_aliases"])) { } QJsonObject toJson() const { - return { { key1, Quotient::toJson(value1) }, - { key2, Quotient::toJson(value2) } }; + return { { "alias", Quotient::toJson(canonicalAlias) }, + { "alt_aliases", Quotient::toJson(altAliases) } }; } - public: - T1 value1; - T2 value2; - - protected: - QString key1; - QString key2; + QString canonicalAlias; + QStringList altAliases; }; } // namespace EventContent class RoomCanonicalAliasEvent - : public StateEvent<EventContent::SimpleDualContent<QString, QStringList>> { + : public StateEvent<EventContent::AliasesEventContent> { 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()) + : StateEvent(typeId(), obj) { } - // Because, MSC2432 specifies, that alt_aliases may be present - // without aliases as well - explicit RoomCanonicalAliasEvent(const QStringList& value2) - : RoomCanonicalAliasEvent(QString(), value2) + RoomCanonicalAliasEvent(const QString& canonicalAlias, const QStringList& altAliases = {}) + : StateEvent(typeId(), matrixTypeId(), QString(), + canonicalAlias, altAliases) { } - template <typename T1, typename T2> - RoomCanonicalAliasEvent(T1&& value1, T2&& value2) + RoomCanonicalAliasEvent(QString&& canonicalAlias, QStringList&& altAliases = {}) : StateEvent(typeId(), matrixTypeId(), QString(), - QStringLiteral("alias"), std::forward<T1>(value1), - QStringLiteral("alt_aliases"), std::forward<T2>(value2)) + std::move(canonicalAlias), std::move(altAliases)) { } - QString alias() const { return content().value1; } + QString alias() const { return content().canonicalAlias; } - QStringList alt_aliases() const { return content().value2; } + QStringList altAliases() const { return content().altAliases; } }; REGISTER_EVENT_TYPE(RoomCanonicalAliasEvent) } // namespace Quotient |