1 /****************************************************************************** 2 * Copyright (C) 2020 QMatrixClient project 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #pragma once 20 21 #include "stateevent.h" 22 23 namespace Quotient { 24 namespace EventContent{ 25 class AliasesEventContent { 26 27 public: 28 29 template<typename T1, typename T2> AliasesEventContent(T1 && canonicalAlias,T2 && altAliases)30 AliasesEventContent(T1&& canonicalAlias, T2&& altAliases) 31 : canonicalAlias(std::forward<T1>(canonicalAlias)) 32 , altAliases(std::forward<T2>(altAliases)) 33 { } 34 AliasesEventContent(const QJsonObject & json)35 AliasesEventContent(const QJsonObject& json) 36 : canonicalAlias(fromJson<QString>(json["alias"])) 37 , altAliases(fromJson<QStringList>(json["alt_aliases"])) 38 { } 39 toJson()40 auto toJson() const 41 { 42 QJsonObject jo; 43 addParam<IfNotEmpty>(jo, QStringLiteral("alias"), canonicalAlias); 44 addParam<IfNotEmpty>(jo, QStringLiteral("alt_aliases"), altAliases); 45 return jo; 46 } 47 48 QString canonicalAlias; 49 QStringList altAliases; 50 }; 51 } // namespace EventContent 52 53 class RoomCanonicalAliasEvent 54 : public StateEvent<EventContent::AliasesEventContent> { 55 public: 56 DEFINE_EVENT_TYPEID("m.room.canonical_alias", RoomCanonicalAliasEvent) 57 RoomCanonicalAliasEvent(const QJsonObject & obj)58 explicit RoomCanonicalAliasEvent(const QJsonObject& obj) 59 : StateEvent(typeId(), obj) 60 { } 61 62 explicit RoomCanonicalAliasEvent(const QString& canonicalAlias, 63 const QStringList& altAliases = {}) StateEvent(typeId (),matrixTypeId (),QString (),canonicalAlias,altAliases)64 : StateEvent(typeId(), matrixTypeId(), QString(), 65 canonicalAlias, altAliases) 66 { } 67 68 explicit RoomCanonicalAliasEvent(QString&& canonicalAlias, 69 QStringList&& altAliases = {}) StateEvent(typeId (),matrixTypeId (),QString (),std::move (canonicalAlias),std::move (altAliases))70 : StateEvent(typeId(), matrixTypeId(), QString(), 71 std::move(canonicalAlias), std::move(altAliases)) 72 { } 73 alias()74 QString alias() const { return content().canonicalAlias; } altAliases()75 QStringList altAliases() const { return content().altAliases; } 76 }; 77 REGISTER_EVENT_TYPE(RoomCanonicalAliasEvent) 78 } // namespace Quotient 79