aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-06-22 20:43:04 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-06-22 20:44:16 +0200
commit6a7e4f883ec22ef26c1d10ba1544b0afd1a0f4d2 (patch)
treeffc31b8c85fa22b4d6d59df28b60360a52ee75b9
parent6a2cec476b72d44ecf1cd05e47724d325a46f246 (diff)
downloadlibquotient-6a7e4f883ec22ef26c1d10ba1544b0afd1a0f4d2.tar.gz
libquotient-6a7e4f883ec22ef26c1d10ba1544b0afd1a0f4d2.zip
Streamline RoomPowerLevelsEvent backoffice code
Also: leave a link at the place in the spec with power level defaults to make it clear they are not invented out of thin air.
-rw-r--r--lib/events/roompowerlevelsevent.cpp38
1 files changed, 12 insertions, 26 deletions
diff --git a/lib/events/roompowerlevelsevent.cpp b/lib/events/roompowerlevelsevent.cpp
index 84a31d55..d9bd010b 100644
--- a/lib/events/roompowerlevelsevent.cpp
+++ b/lib/events/roompowerlevelsevent.cpp
@@ -5,6 +5,8 @@
using namespace Quotient;
+// The default values used below are defined in
+// https://spec.matrix.org/v1.3/client-server-api/#mroompower_levels
PowerLevelsEventContent::PowerLevelsEventContent(const QJsonObject& json) :
invite(json["invite"_ls].toInt(50)),
kick(json["kick"_ls].toInt(50)),
@@ -16,8 +18,7 @@ PowerLevelsEventContent::PowerLevelsEventContent(const QJsonObject& json) :
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)})
-{
-}
+{}
QJsonObject PowerLevelsEventContent::toJson() const
{
@@ -36,32 +37,17 @@ QJsonObject PowerLevelsEventContent::toJson() const
return o;
}
-int RoomPowerLevelsEvent::powerLevelForEvent(const QString &eventId) const {
- auto e = events();
-
- if (e.contains(eventId)) {
- return e[eventId];
- }
-
- return eventsDefault();
+int RoomPowerLevelsEvent::powerLevelForEvent(const QString& eventId) const
+{
+ return events().value(eventId, eventsDefault());
}
-int RoomPowerLevelsEvent::powerLevelForState(const QString &eventId) const {
- auto e = events();
-
- if (e.contains(eventId)) {
- return e[eventId];
- }
-
- return stateDefault();
+int RoomPowerLevelsEvent::powerLevelForState(const QString& eventId) const
+{
+ return events().value(eventId, stateDefault());
}
-int RoomPowerLevelsEvent::powerLevelForUser(const QString &userId) const {
- auto u = users();
-
- if (u.contains(userId)) {
- return u[userId];
- }
-
- return usersDefault();
+int RoomPowerLevelsEvent::powerLevelForUser(const QString& userId) const
+{
+ return users().value(userId, usersDefault());
}