aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlack Hat <bhat@encom.eu.org>2019-12-30 21:55:01 +0800
committerBlack Hat <bhat@encom.eu.org>2019-12-30 21:55:01 +0800
commit00921320a407beaae62d01dbcf1550c3334a9258 (patch)
tree00d11fbed2e51f639d655ca90c304a1c501e5871
parent52fdd715d605f201331a88ffb1d9caafcf86beb1 (diff)
downloadlibquotient-00921320a407beaae62d01dbcf1550c3334a9258.tar.gz
libquotient-00921320a407beaae62d01dbcf1550c3334a9258.zip
Simplify code
-rw-r--r--lib/events/roompowerlevelsevent.cpp36
1 files changed, 5 insertions, 31 deletions
diff --git a/lib/events/roompowerlevelsevent.cpp b/lib/events/roompowerlevelsevent.cpp
index 072f7a95..a6efaa63 100644
--- a/lib/events/roompowerlevelsevent.cpp
+++ b/lib/events/roompowerlevelsevent.cpp
@@ -4,41 +4,15 @@
using namespace Quotient;
-inline QHash<QString, int> qVariantHashToQHash(const QVariantHash& vHash) {
- QHash<QString, int> hash;
-
- QVariantHash::const_iterator i = vHash.constBegin();
-
- while (i != vHash.constEnd()) {
- hash.insert(i.key(), i.value().toInt());
- ++i;
- }
-
- return hash;
-}
-
-inline QJsonObject qHashToJson(const QHash<QString, int>& hash) {
- QJsonObject json;
-
- QHash<QString, int>::const_iterator i = hash.constBegin();
-
- while (i != hash.constEnd()) {
- json.insert(i.key(), i.value());
- ++i;
- }
-
- return json;
-}
-
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(qVariantHashToQHash(json["events"_ls].toVariant().toHash())),
+ events(fromJson<QHash<QString, int>>(json["events"_ls])),
eventsDefault(json["events_default"_ls].toInt(0)),
stateDefault(json["state_default"_ls].toInt(0)),
- users(qVariantHashToQHash(json["users"_ls].toVariant().toHash())),
+ users(fromJson<QHash<QString, int>>(json["users"_ls])),
usersDefault(json["users_default"_ls].toInt(0)),
notifications(Notifications{json["notifications"_ls]["room"_ls].toInt(50)})
{
@@ -49,12 +23,12 @@ void PowerLevelsEventContent::fillJson(QJsonObject* o) const {
o->insert(QStringLiteral("kick"), kick);
o->insert(QStringLiteral("ban"), ban);
o->insert(QStringLiteral("redact"), redact);
- o->insert(QStringLiteral("events"), qHashToJson(events));
+ o->insert(QStringLiteral("events"), Quotient::toJson(events));
o->insert(QStringLiteral("events_default"), eventsDefault);
o->insert(QStringLiteral("state_default"), stateDefault);
- o->insert(QStringLiteral("users"), qHashToJson(users));
+ o->insert(QStringLiteral("users"), Quotient::toJson(users));
o->insert(QStringLiteral("users_default"), usersDefault);
- o->insert(QStringLiteral("notifications"), QJsonObject{{"room", notifications.room}});
+ o->insert(QStringLiteral("notifications"), {{"room", notifications.room}});
}
int RoomPowerLevelsEvent::powerLevelForEvent(const QString &eventId) {