aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-02-16 20:00:46 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-02-16 20:00:46 +0900
commit7e9bf3911e0457bf5af21672d4325882584b78ad (patch)
tree4202400e16bc6ba60cfe4ebb0b2322accf0af47a /lib
parent4e2de22c7d327836d2fe44764f8c7855a51f6206 (diff)
downloadlibquotient-7e9bf3911e0457bf5af21672d4325882584b78ad.tar.gz
libquotient-7e9bf3911e0457bf5af21672d4325882584b78ad.zip
Room::canSwitchVersions()
Diffstat (limited to 'lib')
-rw-r--r--lib/room.cpp40
-rw-r--r--lib/room.h3
2 files changed, 26 insertions, 17 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 3a37053d..538c1562 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -573,6 +573,26 @@ void Room::markAllMessagesAsRead()
d->markMessagesAsRead(d->timeline.crbegin());
}
+bool Room::canSwitchVersions() const
+{
+ // TODO, #276: m.room.power_levels
+ const auto* plEvt =
+ d->currentState.value({"m.room.power_levels", ""});
+ 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").toObject()
+ .value("m.room.tombstone"_ls).toInt(
+ plJson.value("state_default"_ls).toInt());
+ return currentUserLevel >= tombstonePowerLevel;
+}
+
bool Room::hasUnreadMessages() const
{
return unreadCount() >= 0;
@@ -1622,24 +1642,10 @@ void Room::checkVersion()
{
qCDebug(MAIN) << this << "version is" << version()
<< "which the server doesn't count as stable";
- // TODO, #276: m.room.power_levels
- if (const auto* plEvt =
- d->currentState.value({"m.room.power_levels", ""}))
+ if (canSwitchVersions())
{
- 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").toObject()
- .value("m.room.tombstone"_ls).toInt(
- plJson.value("state_default"_ls).toInt());
- if (currentUserLevel >= tombstonePowerLevel)
- {
- qCDebug(MAIN) << "The current user has enough privileges to fix it";
- emit unstableVersion(defaultVersion, stableVersions);
- }
+ qCDebug(MAIN) << "The current user has enough privileges to fix it";
+ emit unstableVersion(defaultVersion, stableVersions);
}
}
}
diff --git a/lib/room.h b/lib/room.h
index e09da94c..f12627f3 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -424,6 +424,9 @@ namespace QMatrixClient
/// 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);