blob: c68e81494b9796122d057c377c7b4b81d7bd3f98 (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// SPDX-FileCopyrightText: 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_(std::move(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))));
}
int
Permissions::defaultLevel()
{
return static_cast<int>(pl.users_default);
}
int
Permissions::redactLevel()
{
return static_cast<int>(pl.redact);
}
int
Permissions::changeLevel(int eventType)
{
return static_cast<int>(pl.state_level(to_string(
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType)))));
}
int
Permissions::sendLevel(int eventType)
{
return static_cast<int>(pl.event_level(to_string(
qml_mtx_events::fromRoomEventType(static_cast<qml_mtx_events::EventType>(eventType)))));
}
bool
Permissions::canPingRoom()
{
return pl.user_level(http::client()->user_id().to_string()) >=
pl.notification_level(mtx::events::state::notification_keys::room);
}
|