From 1d7575036e4682961c4696d25311e2d8cc9ce293 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 5 Sep 2022 02:00:20 +0200 Subject: [PATCH] Allow creating spaces --- CMakeLists.txt | 2 +- io.github.NhekoReborn.Nheko.yaml | 2 +- resources/qml/RoomList.qml | 9 +++++++++ resources/qml/dialogs/CreateRoom.qml | 11 +++++++++-- src/timeline/CommunitiesModel.cpp | 23 ++++++++++++++++------- src/ui/NhekoGlobalObject.cpp | 14 +++++++++++++- src/ui/NhekoGlobalObject.h | 8 ++++++-- 7 files changed, 55 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86377da2..a2989880 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -582,7 +582,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG 43e88905659b027bc47c40fe0d31cf28fd639ef9 + GIT_TAG a00a04adaddf856feaa21087217608e05b9c7ed3 ) set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "") set(BUILD_LIB_TESTS OFF CACHE INTERNAL "") diff --git a/io.github.NhekoReborn.Nheko.yaml b/io.github.NhekoReborn.Nheko.yaml index 1ce2f69d..d0c065d5 100644 --- a/io.github.NhekoReborn.Nheko.yaml +++ b/io.github.NhekoReborn.Nheko.yaml @@ -203,7 +203,7 @@ modules: buildsystem: cmake-ninja name: mtxclient sources: - - commit: 43e88905659b027bc47c40fe0d31cf28fd639ef9 + - commit: a00a04adaddf856feaa21087217608e05b9c7ed3 #tag: v0.8.0 type: git url: https://github.com/Nheko-Reborn/mtxclient.git diff --git a/resources/qml/RoomList.qml b/resources/qml/RoomList.qml index d920b97b..5ce69d97 100644 --- a/resources/qml/RoomList.qml +++ b/resources/qml/RoomList.qml @@ -729,6 +729,15 @@ Page { } } + Platform.MenuItem { + text: qsTr("Create a new community") + onTriggered: { + var createRoom = createRoomComponent.createObject(timelineRoot, { "space": true }); + createRoom.show(); + timelineRoot.destroyOnClose(createRoom); + } + } + } } diff --git a/resources/qml/dialogs/CreateRoom.qml b/resources/qml/dialogs/CreateRoom.qml index 03534327..d6668b86 100644 --- a/resources/qml/dialogs/CreateRoom.qml +++ b/resources/qml/dialogs/CreateRoom.qml @@ -12,7 +12,10 @@ import im.nheko 1.0 ApplicationWindow { id: createRoomRoot - title: qsTr("Create Room") + + property bool space: false + + title: space ? qsTr("New community") : qsTr("New Room") minimumWidth: Math.max(rootLayout.implicitWidth+2*rootLayout.anchors.margins, footer.implicitWidth + Nheko.paddingLarge) minimumHeight: rootLayout.implicitHeight+footer.implicitHeight+2*rootLayout.anchors.margins modality: Qt.NonModal @@ -95,6 +98,7 @@ ApplicationWindow { checked: false } Label { + visible: !space Layout.preferredWidth: implicitWidth Layout.alignment: Qt.AlignLeft text: qsTr("Trusted") @@ -107,6 +111,7 @@ ApplicationWindow { ToolTip.delay: Nheko.tooltipDelay } ToggleButton { + visible: !space Layout.alignment: Qt.AlignRight Layout.preferredWidth: implicitWidth id: isTrusted @@ -114,6 +119,7 @@ ApplicationWindow { enabled: !isPublic.checked } Label { + visible: !space Layout.preferredWidth: implicitWidth Layout.alignment: Qt.AlignLeft text: qsTr("Encryption") @@ -126,6 +132,7 @@ ApplicationWindow { ToolTip.delay: Nheko.tooltipDelay } ToggleButton { + visible: !space Layout.alignment: Qt.AlignRight Layout.preferredWidth: implicitWidth id: isEncrypted @@ -150,7 +157,7 @@ ApplicationWindow { else { preset = isTrusted.checked ? 2 : 0; } - Nheko.createRoom(newRoomName.text, newRoomTopic.text, newRoomAlias.text, isEncrypted.checked, preset) + Nheko.createRoom(space, newRoomName.text, newRoomTopic.text, newRoomAlias.text, isEncrypted.checked, preset) createRoomRoot.close(); } } diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp index adc52c7b..72d0bdfb 100644 --- a/src/timeline/CommunitiesModel.cpp +++ b/src/timeline/CommunitiesModel.cpp @@ -449,7 +449,8 @@ CommunitiesModel::clear() void CommunitiesModel::sync(const mtx::responses::Sync &sync_) { - bool tagsUpdated = false; + bool tagsUpdated = false; + const auto userid = http::client()->user_id().to_string(); for (const auto &[roomid, room] : sync_.rooms.join) { for (const auto &e : room.account_data.events) @@ -457,20 +458,28 @@ CommunitiesModel::sync(const mtx::responses::Sync &sync_) mtx::events::AccountDataEvent>(e)) { tagsUpdated = true; } - for (const auto &e : room.state.events) + for (const auto &e : room.state.events) { if (std::holds_alternative>( e) || std::holds_alternative>( - e)) { + e)) tagsUpdated = true; - } - for (const auto &e : room.timeline.events) + + if (auto ev = std::get_if>(&e); + ev && ev->state_key == userid) + tagsUpdated = true; + } + for (const auto &e : room.timeline.events) { if (std::holds_alternative>( e) || std::holds_alternative>( - e)) { + e)) tagsUpdated = true; - } + + if (auto ev = std::get_if>(&e); + ev && ev->state_key == userid) + tagsUpdated = true; + } auto roomId = QString::fromStdString(roomid); auto &oldUnreads = roomNotificationCache[roomId]; diff --git a/src/ui/NhekoGlobalObject.cpp b/src/ui/NhekoGlobalObject.cpp index ce094205..b24e68a9 100644 --- a/src/ui/NhekoGlobalObject.cpp +++ b/src/ui/NhekoGlobalObject.cpp @@ -136,10 +136,22 @@ Nheko::setTransientParent(QWindow *window, QWindow *parentWindow) const } void -Nheko::createRoom(QString name, QString topic, QString aliasLocalpart, bool isEncrypted, int preset) +Nheko::createRoom(bool space, + QString name, + QString topic, + QString aliasLocalpart, + bool isEncrypted, + int preset) { mtx::requests::CreateRoom req; + if (space) { + req.creation_content = mtx::events::state::Create{}; + req.creation_content->type = mtx::events::state::room_type::space; + req.creation_content->creator.clear(); + req.creation_content->room_version.clear(); + } + switch (preset) { case 1: req.preset = mtx::requests::Preset::PublicChat; diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h index a63c7846..e9034ebc 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h @@ -56,8 +56,12 @@ public: Q_INVOKABLE void setStatusMessage(QString msg) const; Q_INVOKABLE void showUserSettingsPage() const; Q_INVOKABLE void logout() const; - Q_INVOKABLE void - createRoom(QString name, QString topic, QString aliasLocalpart, bool isEncrypted, int preset); + Q_INVOKABLE void createRoom(bool space, + QString name, + QString topic, + QString aliasLocalpart, + bool isEncrypted, + int preset); Q_INVOKABLE PowerlevelEditingModels *editPowerlevels(QString room_id_) const { return new PowerlevelEditingModels(room_id_);