aboutsummaryrefslogtreecommitdiff
path: root/lib/events/roomcanonicalaliasevent.h
blob: e1c7888e153463ae027f0532a6d32d9936049c6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-FileCopyrightText: 2020 Ram Nad <ramnad1999@gmail.com>
// SPDX-FileCopyrightText: 2020 Kitsune Ral <Kitsune-Ral@users.sf.net>
// SPDX-License-Identifier: LGPL-2.1-or-later
 
#pragma once

#include "stateevent.h"

namespace Quotient {
namespace EventContent {
    struct AliasesEventContent {
        QString canonicalAlias;
        QStringList altAliases;
    };
} // namespace EventContent

template<>
inline EventContent::AliasesEventContent fromJson(const QJsonObject& jo)
{
    return EventContent::AliasesEventContent {
        fromJson<QString>(jo["alias"_ls]),
        fromJson<QStringList>(jo["alt_aliases"_ls])
    };
}
template<>
inline auto toJson(const EventContent::AliasesEventContent& c)
{
    QJsonObject jo;
    addParam<IfNotEmpty>(jo, QStringLiteral("alias"), c.canonicalAlias);
    addParam<IfNotEmpty>(jo, QStringLiteral("alt_aliases"), c.altAliases);
    return jo;
}

class QUOTIENT_API RoomCanonicalAliasEvent
    : public StateEvent<EventContent::AliasesEventContent> {
public:
    QUO_EVENT(RoomCanonicalAliasEvent, "m.room.canonical_alias")

    explicit RoomCanonicalAliasEvent(const QJsonObject& obj)
        : StateEvent(typeId(), obj)
    { }

    explicit RoomCanonicalAliasEvent(const QString& canonicalAlias,
                                     const QStringList& altAliases = {})
        : StateEvent(typeId(), matrixTypeId(), {},
                canonicalAlias, altAliases)
    { }

    explicit RoomCanonicalAliasEvent(QString&& canonicalAlias,
                                     QStringList&& altAliases = {})
        : StateEvent(typeId(), matrixTypeId(), {},
                std::move(canonicalAlias), std::move(altAliases))
    { }

    QString alias() const { return content().canonicalAlias; }
    QStringList altAliases() const { return content().altAliases; }
};
} // namespace Quotient