diff options
author | Andres Salomon <dilinger@queued.net> | 2021-01-18 04:00:14 -0500 |
---|---|---|
committer | Andres Salomon <dilinger@queued.net> | 2021-01-18 04:00:14 -0500 |
commit | 09eb39236666e81d5da014acea011dcd74d0999b (patch) | |
tree | 52876d96be71be1a39d5d935c1295a51995e8949 /lib/events/roomcanonicalaliasevent.h | |
parent | f1788ee27f33e9339334e0d79bde9a27d9ce2e44 (diff) | |
parent | a4e78956f105875625b572d8b98459ffa86fafe5 (diff) | |
download | libquotient-09eb39236666e81d5da014acea011dcd74d0999b.tar.gz libquotient-09eb39236666e81d5da014acea011dcd74d0999b.zip |
Update upstream source from tag 'upstream/0.6.4'
Update to upstream version '0.6.4'
with Debian dir aa8705fd74743e79c043bc9e3e425d5064404cfe
Diffstat (limited to 'lib/events/roomcanonicalaliasevent.h')
-rw-r--r-- | lib/events/roomcanonicalaliasevent.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/events/roomcanonicalaliasevent.h b/lib/events/roomcanonicalaliasevent.h new file mode 100644 index 00000000..fadfece0 --- /dev/null +++ b/lib/events/roomcanonicalaliasevent.h @@ -0,0 +1,78 @@ +/****************************************************************************** + * Copyright (C) 2020 QMatrixClient project + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#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; + } + + QString canonicalAlias; + QStringList altAliases; + }; +} // namespace EventContent + +class RoomCanonicalAliasEvent + : public StateEvent<EventContent::AliasesEventContent> { +public: + DEFINE_EVENT_TYPEID("m.room.canonical_alias", RoomCanonicalAliasEvent) + + explicit RoomCanonicalAliasEvent(const QJsonObject& obj) + : StateEvent(typeId(), obj) + { } + + explicit RoomCanonicalAliasEvent(const QString& canonicalAlias, + const QStringList& altAliases = {}) + : StateEvent(typeId(), matrixTypeId(), QString(), + canonicalAlias, altAliases) + { } + + explicit RoomCanonicalAliasEvent(QString&& canonicalAlias, + QStringList&& altAliases = {}) + : StateEvent(typeId(), matrixTypeId(), QString(), + std::move(canonicalAlias), std::move(altAliases)) + { } + + QString alias() const { return content().canonicalAlias; } + QStringList altAliases() const { return content().altAliases; } +}; +REGISTER_EVENT_TYPE(RoomCanonicalAliasEvent) +} // namespace Quotient |