summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-06-16 22:59:41 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-06-25 11:34:18 +0200
commit6bfa6c4c793f1cd74df64d593ff2060ff94f176f (patch)
treeeb1e153e214cdb37ff8f75d2f559f3991eaac9da /src/timeline
parentupdate SingleApplication (diff)
downloadnheko-6bfa6c4c793f1cd74df64d593ff2060ff94f176f.tar.xz
Allow filtering by space
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/CommunitiesModel.cpp9
-rw-r--r--src/timeline/RoomlistModel.cpp24
-rw-r--r--src/timeline/RoomlistModel.h3
3 files changed, 36 insertions, 0 deletions
diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp
index 88464bf9..6ff953d2 100644
--- a/src/timeline/CommunitiesModel.cpp
+++ b/src/timeline/CommunitiesModel.cpp
@@ -185,6 +185,15 @@ CommunitiesModel::setCurrentTagId(QString tagId)
                                 return;
                         }
                 }
+        } else if (tagId.startsWith("space:")) {
+                auto tag = tagId.mid(6);
+                for (const auto &t : spaceOrder_) {
+                        if (t == tag) {
+                                this->currentTagId_ = tagId;
+                                emit currentTagIdChanged(currentTagId_);
+                                return;
+                        }
+                }
         }
 
         this->currentTagId_ = "";
diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index 0f980c6c..3b6ad54a 100644
--- a/src/timeline/RoomlistModel.cpp
+++ b/src/timeline/RoomlistModel.cpp
@@ -530,6 +530,30 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons
                                         return false;
                 }
                 return true;
+        } else if (filterType == FilterBy::Space) {
+                auto roomid = sourceModel()
+                                ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::RoomId)
+                                .toString();
+                auto tags = sourceModel()
+                              ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags)
+                              .toStringList();
+
+                auto contains = [](const std::vector<std::string> &v, const std::string &str) {
+                        for (const auto &e : v)
+                                if (e == str)
+                                        return true;
+                        return false;
+                };
+                auto parents = cache::client()->getParentRoomIds(roomid.toStdString());
+
+                if (!contains(parents, filterStr.toStdString()))
+                        return false;
+                else if (!hiddenTags.empty()) {
+                        for (const auto &t : tags)
+                                if (hiddenTags.contains(t))
+                                        return false;
+                }
+                return true;
         } else {
                 return true;
         }
diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h
index b0244886..5f8b8bd8 100644
--- a/src/timeline/RoomlistModel.h
+++ b/src/timeline/RoomlistModel.h
@@ -134,6 +134,9 @@ public slots:
                 if (tagId.startsWith("tag:")) {
                         filterType = FilterBy::Tag;
                         filterStr  = tagId.mid(4);
+                } else if (tagId.startsWith("space:")) {
+                        filterType = FilterBy::Space;
+                        filterStr  = tagId.mid(6);
                 } else {
                         filterType = FilterBy::Nothing;
                         filterStr.clear();