diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 4f69ce58f..36d9fd498 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -94,6 +94,7 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS connect(this, &Room::changed, this, [this] { Q_EMIT canEncryptRoomChanged(); }); + connect(connection, &Connection::capabilitiesLoaded, this, &NeoChatRoom::maxRoomVersionChanged); } void NeoChatRoom::uploadFile(const QUrl &url, const QString &body) @@ -1370,3 +1371,14 @@ void NeoChatRoom::setCanonicalAlias(const QString &newAlias) } }); } + +int NeoChatRoom::maxRoomVersion() const +{ + int maxVersion = 0; + for (auto roomVersion : connection()->availableRoomVersions()) { + if (roomVersion.id.toInt() > maxVersion) { + maxVersion = roomVersion.id.toInt(); + } + } + return maxVersion; +} diff --git a/src/neochatroom.h b/src/neochatroom.h index 17918cd16..2092af15a 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -65,6 +65,13 @@ class NeoChatRoom : public Quotient::Room Q_PROPERTY(QString chatBoxAttachmentPath READ chatBoxAttachmentPath WRITE setChatBoxAttachmentPath NOTIFY chatBoxAttachmentPathChanged) Q_PROPERTY(bool canEncryptRoom READ canEncryptRoom NOTIFY canEncryptRoomChanged) + /** + * @brief Get the maximum room version that the server supports. + * + * Only returns main integer room versions (i.e. no msc room versions). + */ + Q_PROPERTY(int maxRoomVersion READ maxRoomVersion NOTIFY maxRoomVersionChanged) + public: enum MessageType { Positive, @@ -223,6 +230,8 @@ public: } #endif + int maxRoomVersion() const; + private: QSet highlights; @@ -274,6 +283,7 @@ Q_SIGNALS: void canEncryptRoomChanged(); void joinRuleChanged(); void historyVisibilityChanged(); + void maxRoomVersionChanged(); public Q_SLOTS: void uploadFile(const QUrl &url, const QString &body = QString()); diff --git a/src/qml/RoomSettings/General.qml b/src/qml/RoomSettings/General.qml index 297be8e74..03d274458 100644 --- a/src/qml/RoomSettings/General.qml +++ b/src/qml/RoomSettings/General.qml @@ -126,6 +126,25 @@ Kirigami.ScrollablePage { MobileForm.FormTextDelegate { text: i18n("Room version") description: room.version + + contentItem.children: QQC2.Button { + visible: room.canSwitchVersions() + enabled: room.version < room.maxRoomVersion + text: i18n("Upgrade Room") + icon.name: "arrow-up-double" + + onClicked: { + if (room.canSwitchVersions()) { + roomUpgradeSheet.currentRoomVersion = room.version + roomUpgradeSheet.open() + } + } + + QQC2.ToolTip { + text: text + delay: Kirigami.Units.toolTipDelay + } + } } } } @@ -264,6 +283,30 @@ Kirigami.ScrollablePage { OpenFileDialog {} } + + Kirigami.OverlaySheet { + id: roomUpgradeSheet + + property var currentRoomVersion + + title: i18n("Upgrade the Room") + Kirigami.FormLayout { + QQC2.SpinBox { + id: spinBox + Kirigami.FormData.label: i18n("Select new version") + from: room.version + to: room.maxRoomVersion + value: room.version + } + QQC2.Button { + text: i18n("Confirm") + onClicked: { + room.switchVersion(spinBox.value) + roomUpgradeSheet.close() + } + } + } + } } }