libQuotient
A Qt library for building matrix clients
roomcanonicalaliasevent.h
Go to the documentation of this file.
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  fromJson<QString>(jo["alias"_L1]),
22  fromJson<QStringList>(jo["alt_aliases"_L1])
23  };
24 }
25 template<>
26 inline auto toJson(const EventContent::AliasesEventContent& c)
27 {
28  QJsonObject jo;
29  addParam<IfNotEmpty>(jo, "alias"_L1, c.canonicalAlias);
30  addParam<IfNotEmpty>(jo, "alt_aliases"_L1, 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