blob: e495704514e851bda0c9eba21b2685dc2de67552 (
plain) (
blame)
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
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "Permissions.h"
#include "Cache_p.h"
#include "MatrixClient.h"
#include "TimelineModel.h"
Permissions::Permissions(QString roomId, QObject *parent)
: QObject(parent)
, roomId_(roomId)
{
invalidate();
}
void
Permissions::invalidate()
{
pl = cache::client()
->getStateEvent<mtx::events::state::PowerLevels>(roomId_.toStdString())
.value_or(mtx::events::StateEvent<mtx::events::state::PowerLevels>{})
.content;
}
bool
Permissions::canInvite()
{
return pl.user_level(http::client()->user_id().to_string()) >= pl.invite;
}
bool
Permissions::canBan()
{
return pl.user_level(http::client()->user_id().to_string()) >= pl.ban;
}
bool
Permissions::canKick()
{
return pl.user_level(http::client()->user_id().to_string()) >= pl.kick;
}
bool
Permissions::canRedact()
{
return pl.user_level(http::client()->user_id().to_string()) >= pl.redact;
}
bool
Permissions::canChange(int eventType)
{
return pl.user_level(http::client()->user_id().to_string()) >=
pl.state_level(to_string(qml_mtx_events::fromRoomEventType(
static_cast<qml_mtx_events::EventType>(eventType))));
}
bool
Permissions::canSend(int eventType)
{
return pl.user_level(http::client()->user_id().to_string()) >=
pl.event_level(to_string(qml_mtx_events::fromRoomEventType(
static_cast<qml_mtx_events::EventType>(eventType))));
}
|