aboutsummaryrefslogtreecommitdiff
path: root/lib/events/roompowerlevelsevent.cpp
diff options
context:
space:
mode:
authorAndres Salomon <dilinger@queued.net>2021-01-18 04:00:14 -0500
committerAndres Salomon <dilinger@queued.net>2021-01-18 04:00:14 -0500
commit09eb39236666e81d5da014acea011dcd74d0999b (patch)
tree52876d96be71be1a39d5d935c1295a51995e8949 /lib/events/roompowerlevelsevent.cpp
parentf1788ee27f33e9339334e0d79bde9a27d9ce2e44 (diff)
parenta4e78956f105875625b572d8b98459ffa86fafe5 (diff)
downloadlibquotient-09eb39236666e81d5da014acea011dcd74d0999b.tar.gz
libquotient-09eb39236666e81d5da014acea011dcd74d0999b.zip
Update upstream source from tag 'upstream/0.6.4'
Update to upstream version '0.6.4' with Debian dir aa8705fd74743e79c043bc9e3e425d5064404cfe
Diffstat (limited to 'lib/events/roompowerlevelsevent.cpp')
-rw-r--r--lib/events/roompowerlevelsevent.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/events/roompowerlevelsevent.cpp b/lib/events/roompowerlevelsevent.cpp
new file mode 100644
index 00000000..0a401752
--- /dev/null
+++ b/lib/events/roompowerlevelsevent.cpp
@@ -0,0 +1,62 @@
+#include "roompowerlevelsevent.h"
+
+#include <QJsonDocument>
+
+using namespace Quotient;
+
+PowerLevelsEventContent::PowerLevelsEventContent(const QJsonObject& json) :
+ invite(json["invite"_ls].toInt(50)),
+ kick(json["kick"_ls].toInt(50)),
+ ban(json["ban"_ls].toInt(50)),
+ redact(json["redact"_ls].toInt(50)),
+ events(fromJson<QHash<QString, int>>(json["events"_ls])),
+ eventsDefault(json["events_default"_ls].toInt(0)),
+ stateDefault(json["state_default"_ls].toInt(0)),
+ users(fromJson<QHash<QString, int>>(json["users"_ls])),
+ usersDefault(json["users_default"_ls].toInt(0)),
+ notifications(Notifications{json["notifications"_ls].toObject()["room"_ls].toInt(50)})
+{
+}
+
+void PowerLevelsEventContent::fillJson(QJsonObject* o) const {
+ o->insert(QStringLiteral("invite"), invite);
+ o->insert(QStringLiteral("kick"), kick);
+ o->insert(QStringLiteral("ban"), ban);
+ o->insert(QStringLiteral("redact"), redact);
+ o->insert(QStringLiteral("events"), Quotient::toJson(events));
+ o->insert(QStringLiteral("events_default"), eventsDefault);
+ o->insert(QStringLiteral("state_default"), stateDefault);
+ o->insert(QStringLiteral("users"), Quotient::toJson(users));
+ o->insert(QStringLiteral("users_default"), usersDefault);
+ o->insert(QStringLiteral("notifications"), QJsonObject{{"room", notifications.room}});
+}
+
+int RoomPowerLevelsEvent::powerLevelForEvent(const QString &eventId) const {
+ auto e = events();
+
+ if (e.contains(eventId)) {
+ return e[eventId];
+ }
+
+ return eventsDefault();
+}
+
+int RoomPowerLevelsEvent::powerLevelForState(const QString &eventId) const {
+ auto e = events();
+
+ if (e.contains(eventId)) {
+ return e[eventId];
+ }
+
+ return stateDefault();
+}
+
+int RoomPowerLevelsEvent::powerLevelForUser(const QString &userId) const {
+ auto u = users();
+
+ if (u.contains(userId)) {
+ return u[userId];
+ }
+
+ return usersDefault();
+}