aboutsummaryrefslogtreecommitdiff
path: root/lib/events/roompowerlevelsevent.h
blob: 7ac12db0bf92c8ec628e2f7232397ac5353e4a81 (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
59
60
61
62
63
64
// SPDX-FileCopyrightText: 2019 Black Hat <bhat@encom.eu.org>
// SPDX-License-Identifier: LGPL-2.1-or-later

#pragma once

#include "stateevent.h"

namespace Quotient {
struct QUOTIENT_API PowerLevelsEventContent {
    struct Notifications {
        int room;
    };

    explicit PowerLevelsEventContent(const QJsonObject& json);
    QJsonObject toJson() const;

    int invite;
    int kick;
    int ban;

    int redact;

    QHash<QString, int> events;
    int eventsDefault;
    int stateDefault;

    QHash<QString, int> users;
    int usersDefault;

    Notifications notifications;
};

class QUOTIENT_API RoomPowerLevelsEvent
    : public StateEvent<PowerLevelsEventContent> {
public:
    QUO_EVENT(RoomPowerLevelsEvent, "m.room.power_levels")

    explicit RoomPowerLevelsEvent(PowerLevelsEventContent&& content)
        : StateEvent(typeId(), matrixTypeId(), QString(), std::move(content))
    {}
    explicit RoomPowerLevelsEvent(const QJsonObject& obj)
        : StateEvent(typeId(), obj)
    {}

    int invite() const { return content().invite; }
    int kick() const { return content().kick; }
    int ban() const { return content().ban; }

    int redact() const { return content().redact; }

    QHash<QString, int> events() const { return content().events; }
    int eventsDefault() const { return content().eventsDefault; }
    int stateDefault() const { return content().stateDefault; }

    QHash<QString, int> users() const { return content().users; }
    int usersDefault() const { return content().usersDefault; }

    int roomNotification() const { return content().notifications.room; }

    int powerLevelForEvent(const QString& eventId) const;
    int powerLevelForState(const QString& eventId) const;
    int powerLevelForUser(const QString& userId) const;
};
} // namespace Quotient