summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2022-09-05 02:00:20 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2022-09-05 02:00:20 +0200
commit1d7575036e4682961c4696d25311e2d8cc9ce293 (patch)
treedad0ed24c1985083c2fd98a498783afa6c173338 /src
parentAttribute values can contain slashes (diff)
downloadnheko-1d7575036e4682961c4696d25311e2d8cc9ce293.tar.xz
Allow creating spaces
Diffstat (limited to 'src')
-rw-r--r--src/timeline/CommunitiesModel.cpp23
-rw-r--r--src/ui/NhekoGlobalObject.cpp14
-rw-r--r--src/ui/NhekoGlobalObject.h8
3 files changed, 35 insertions, 10 deletions
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<mtx::events::account_data::Tags>>(e)) {
                 tagsUpdated = true;
             }
-        for (const auto &e : room.state.events)
+        for (const auto &e : room.state.events) {
             if (std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Child>>(
                   e) ||
                 std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Parent>>(
-                  e)) {
+                  e))
                 tagsUpdated = true;
-            }
-        for (const auto &e : room.timeline.events)
+
+            if (auto ev = std::get_if<mtx::events::StateEvent<mtx::events::state::Member>>(&e);
+                ev && ev->state_key == userid)
+                tagsUpdated = true;
+        }
+        for (const auto &e : room.timeline.events) {
             if (std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Child>>(
                   e) ||
                 std::holds_alternative<mtx::events::StateEvent<mtx::events::state::space::Parent>>(
-                  e)) {
+                  e))
                 tagsUpdated = true;
-            }
+
+            if (auto ev = std::get_if<mtx::events::StateEvent<mtx::events::state::Member>>(&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_);