diff options
author | Black Hat <bhat@encom.eu.org> | 2020-01-12 04:29:14 -0800 |
---|---|---|
committer | Black Hat <bhat@encom.eu.org> | 2020-01-12 04:29:14 -0800 |
commit | ac48199de174aa8cca52e703a3e65034fcd5db07 (patch) | |
tree | 11286e7a13267624da5e3cbf06794fc0ce9c896d /lib/room.cpp | |
parent | 3accf7dfd82e8e14a7f90a8debee921f2f428679 (diff) | |
download | libquotient-ac48199de174aa8cca52e703a3e65034fcd5db07.tar.gz libquotient-ac48199de174aa8cca52e703a3e65034fcd5db07.zip |
Use parsed RoomPowerLevelsEvent in room upgrading
Diffstat (limited to 'lib/room.cpp')
-rw-r--r-- | lib/room.cpp | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index 696a5f1b..b29f6f48 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -52,6 +52,7 @@ #include "events/roomtombstoneevent.h" #include "events/simplestateevents.h" #include "events/typingevent.h" +#include "events/roompowerlevelsevent.h" #include "jobs/downloadfilejob.h" #include "jobs/mediathumbnailjob.h" #include "jobs/postreadmarkersjob.h" @@ -656,21 +657,12 @@ bool Room::canSwitchVersions() const // TODO, #276: m.room.power_levels const auto* plEvt = - d->currentState.value({ QStringLiteral("m.room.power_levels"), {} }); + d->getCurrentState<RoomPowerLevelsEvent>(); if (!plEvt) return true; - const auto plJson = plEvt->contentJson(); - const auto currentUserLevel = - plJson.value("users"_ls) - .toObject() - .value(localUser()->id()) - .toInt(plJson.value("users_default"_ls).toInt()); - const auto tombstonePowerLevel = - plJson.value("events"_ls) - .toObject() - .value("m.room.tombstone"_ls) - .toInt(plJson.value("state_default"_ls).toInt()); + const auto currentUserLevel = plEvt->powerLevelForUser(localUser()->id()); + const auto tombstonePowerLevel = plEvt->powerLevelForState("m.room.tombstone"_ls); return currentUserLevel >= tombstonePowerLevel; } |