1 | // SPDX-FileCopyrightText: 2020 Ram Nad <ramnad1999@gmail.com> |
2 | // SPDX-FileCopyrightText: 2020 Kitsune Ral <Kitsune-Ral@users.sf.net> |
3 | // SPDX-License-Identifier: LGPL-2.1-or-later |
4 | |
5 | #pragma once |
6 | |
7 | #include "stateevent.h" |
8 | |
9 | namespace Quotient { |
10 | namespace EventContent { |
11 | struct AliasesEventContent { |
12 | QString canonicalAlias; |
13 | QStringList altAliases; |
14 | }; |
15 | } // namespace EventContent |
16 | |
17 | template<> |
18 | inline EventContent::AliasesEventContent fromJson(const QJsonObject& jo) |
19 | { |
20 | return EventContent::AliasesEventContent { |
21 | .canonicalAlias: fromJson<QString>(jv: jo["alias" _ls]), |
22 | .altAliases: fromJson<QStringList>(json: jo["alt_aliases" _ls]) |
23 | }; |
24 | } |
25 | template<> |
26 | inline auto toJson(const EventContent::AliasesEventContent& c) |
27 | { |
28 | QJsonObject jo; |
29 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("alias" ), value: c.canonicalAlias); |
30 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("alt_aliases" ), value: c.altAliases); |
31 | return jo; |
32 | } |
33 | |
34 | class QUOTIENT_API RoomCanonicalAliasEvent |
35 | : public KeylessStateEventBase<RoomCanonicalAliasEvent, |
36 | EventContent::AliasesEventContent> { |
37 | public: |
38 | QUO_EVENT(RoomCanonicalAliasEvent, "m.room.canonical_alias" ) |
39 | using KeylessStateEventBase::KeylessStateEventBase; |
40 | |
41 | QString alias() const { return content().canonicalAlias; } |
42 | QStringList altAliases() const { return content().altAliases; } |
43 | }; |
44 | } // namespace Quotient |
45 | |