aboutsummaryrefslogtreecommitdiff
path: root/lib/events/roomcreateevent.cpp
blob: e119696ff0337c1853e877f3d5531cf9d05337aa (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
// SPDX-FileCopyrightText: 2019 Kitsune Ral <Kitsune-Ral@users.sf.net>
// SPDX-License-Identifier: LGPL-2.1-or-later

#include "roomcreateevent.h"
#include "logging.h"

using namespace Quotient;

template <>
struct Quotient::JsonConverter<RoomType> {
    static RoomType load(const QJsonValue& jv)
    {
        const auto& roomTypeString = jv.toString();
        for (auto it = RoomTypeStrings.begin(); it != RoomTypeStrings.end();
             ++it)
            if (roomTypeString == *it)
                return RoomType(it - RoomTypeStrings.begin());

        if (!roomTypeString.isEmpty())
            qCWarning(EVENTS) << "Unknown Room Type: " << roomTypeString;
        return RoomType::Undefined;
    }
};

bool RoomCreateEvent::isFederated() const
{
    return fromJson<bool>(contentJson()["m.federate"_ls]);
}

QString RoomCreateEvent::version() const
{
    return fromJson<QString>(contentJson()["room_version"_ls]);
}

RoomCreateEvent::Predecessor RoomCreateEvent::predecessor() const
{
    const auto predJson = contentJson()["predecessor"_ls].toObject();
    return { fromJson<QString>(predJson[RoomIdKeyL]),
             fromJson<QString>(predJson[EventIdKeyL]) };
}

bool RoomCreateEvent::isUpgrade() const
{
    return contentJson().contains("predecessor"_ls);
}

RoomType RoomCreateEvent::roomType() const
{
    return fromJson<RoomType>(contentJson()["type"_ls]);
}