From feb5e82fbe96269f1f7683470b02fbc9c70acaa0 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 12 Apr 2020 10:01:18 +0200 Subject: Room::canSwitchVersions(): refactor and make Q_INVOKABLE --- lib/room.cpp | 16 +++++++--------- lib/room.h | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/room.cpp b/lib/room.cpp index 5d4e2141..dc65ebfc 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -758,15 +758,13 @@ bool Room::canSwitchVersions() const if (!successorId().isEmpty()) return false; // No one can upgrade a room that's already upgraded - // TODO, #276: m.room.power_levels - const auto* plEvt = - d->getCurrentState(); - if (!plEvt) - return true; - - const auto currentUserLevel = plEvt->powerLevelForUser(localUser()->id()); - const auto tombstonePowerLevel = plEvt->powerLevelForState("m.room.tombstone"_ls); - return currentUserLevel >= tombstonePowerLevel; + if (const auto* plEvt = d->getCurrentState()) { + const auto currentUserLevel = plEvt->powerLevelForUser(localUser()->id()); + const auto tombstonePowerLevel = + plEvt->powerLevelForState("m.room.tombstone"_ls); + return currentUserLevel >= tombstonePowerLevel; + } + return true; } bool Room::hasUnreadMessages() const { return unreadCount() >= 0; } diff --git a/lib/room.h b/lib/room.h index a5b933c2..66a8df7a 100644 --- a/lib/room.h +++ b/lib/room.h @@ -474,6 +474,9 @@ public: Q_INVOKABLE bool supportsCalls() const; + /// Whether the current user is allowed to upgrade the room + Q_INVOKABLE bool canSwitchVersions() const; + /// Get a state event with the given event type and state key /*! This method returns a (potentially empty) state event corresponding * to the pair of event type \p evtType and state key \p stateKey. @@ -566,9 +569,6 @@ public slots: /// Mark all messages in the room as read void markAllMessagesAsRead(); - /// Whether the current user is allowed to upgrade the room - bool canSwitchVersions() const; - /// Switch the room's version (aka upgrade) void switchVersion(QString newVersion); -- cgit v1.2.3