From 6bfa6c4c793f1cd74df64d593ff2060ff94f176f Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Wed, 16 Jun 2021 22:59:41 +0200 Subject: Allow filtering by space --- src/timeline/RoomlistModel.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/timeline/RoomlistModel.cpp') 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 &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; } -- cgit 1.5.1 From 0ec7be3090814c7a61273cfe88e5dff9fbaccd91 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 18 Jun 2021 12:10:13 +0200 Subject: Fix hiding rooms from a space --- src/timeline/CommunitiesModel.cpp | 8 +++++- src/timeline/RoomlistModel.cpp | 54 ++++++++++++++++++++++++++++++--------- src/timeline/RoomlistModel.h | 1 + 3 files changed, 50 insertions(+), 13 deletions(-) (limited to 'src/timeline/RoomlistModel.cpp') diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp index 6ff953d2..c66d5949 100644 --- a/src/timeline/CommunitiesModel.cpp +++ b/src/timeline/CommunitiesModel.cpp @@ -214,7 +214,13 @@ CommunitiesModel::toggleTagId(QString tagId) if (tagId.startsWith("tag:")) { auto idx = tags_.indexOf(tagId.mid(4)); if (idx != -1) - emit dataChanged(index(idx), index(idx), {Hidden}); + emit dataChanged(index(idx + 1 + spaceOrder_.size()), + index(idx + 1 + spaceOrder_.size()), + {Hidden}); + } else if (tagId.startsWith("space:")) { + auto idx = spaceOrder_.indexOf(tagId.mid(6)); + if (idx != -1) + emit dataChanged(index(idx + 1), index(idx + 1), {Hidden}); } emit hiddenTagsChanged(); diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index 3b6ad54a..0d9ec66b 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -51,6 +51,7 @@ RoomlistModel::roleNames() const {IsInvite, "isInvite"}, {IsSpace, "isSpace"}, {Tags, "tags"}, + {ParentSpaces, "parentSpaces"}, }; } @@ -93,6 +94,14 @@ RoomlistModel::data(const QModelIndex &index, int role) const list.push_back(QString::fromStdString(t)); return list; } + case Roles::ParentSpaces: { + auto parents = + cache::client()->getParentRoomIds(roomid.toStdString()); + QStringList list; + for (const auto &t : parents) + list.push_back(QString::fromStdString(t)); + return list; + } default: return {}; } @@ -122,6 +131,14 @@ RoomlistModel::data(const QModelIndex &index, int role) const return false; case Roles::Tags: return QStringList(); + case Roles::ParentSpaces: { + auto parents = + cache::client()->getParentRoomIds(roomid.toStdString()); + QStringList list; + for (const auto &t : parents) + list.push_back(QString::fromStdString(t)); + return list; + } default: return {}; } @@ -514,6 +531,14 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons for (const auto &t : tags) if (hiddenTags.contains(t)) return false; + } else if (!hiddenSpaces.empty()) { + auto parents = + sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::ParentSpaces) + .toStringList(); + for (const auto &t : parents) + if (hiddenSpaces.contains(t)) + return false; } return true; @@ -528,30 +553,35 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons for (const auto &t : tags) if (t != filterStr && hiddenTags.contains(t)) return false; + } else if (!hiddenSpaces.empty()) { + auto parents = + sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::ParentSpaces) + .toStringList(); + for (const auto &t : parents) + if (hiddenSpaces.contains(t)) + return false; } return true; } else if (filterType == FilterBy::Space) { - auto roomid = sourceModel() - ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::RoomId) - .toString(); + auto parents = + sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::ParentSpaces) + .toStringList(); auto tags = sourceModel() ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags) .toStringList(); - auto contains = [](const std::vector &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())) + if (!parents.contains(filterStr)) return false; else if (!hiddenTags.empty()) { for (const auto &t : tags) if (hiddenTags.contains(t)) return false; + } else if (!hiddenSpaces.empty()) { + for (const auto &t : parents) + if (hiddenSpaces.contains(t)) + return false; } return true; } else { diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h index 5f8b8bd8..d6cbb462 100644 --- a/src/timeline/RoomlistModel.h +++ b/src/timeline/RoomlistModel.h @@ -38,6 +38,7 @@ public: IsInvite, IsSpace, Tags, + ParentSpaces, }; RoomlistModel(TimelineViewManager *parent = nullptr); -- cgit 1.5.1 From f349b0cce0335c2c9f6aaabfad9315e80bc72677 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 18 Jun 2021 14:05:52 +0200 Subject: Hide spaces by default, unless they are in the current space filter --- src/timeline/CommunitiesModel.cpp | 19 +++++++++++++++++++ src/timeline/RoomlistModel.cpp | 34 ++++++++++++++++++++++++++++++---- src/timeline/TimelineModel.cpp | 4 ++++ src/timeline/TimelineModel.h | 9 ++++++--- 4 files changed, 59 insertions(+), 7 deletions(-) (limited to 'src/timeline/RoomlistModel.cpp') diff --git a/src/timeline/CommunitiesModel.cpp b/src/timeline/CommunitiesModel.cpp index c66d5949..97bfa76d 100644 --- a/src/timeline/CommunitiesModel.cpp +++ b/src/timeline/CommunitiesModel.cpp @@ -167,6 +167,25 @@ CommunitiesModel::sync(const mtx::responses::Rooms &rooms) mtx::events::AccountDataEvent>(e)) { tagsUpdated = true; } + for (const auto &e : room.state.events) + if (std::holds_alternative< + mtx::events::StateEvent>(e) || + std::holds_alternative< + mtx::events::StateEvent>(e)) { + tagsUpdated = true; + } + for (const auto &e : room.timeline.events) + if (std::holds_alternative< + mtx::events::StateEvent>(e) || + std::holds_alternative< + mtx::events::StateEvent>(e)) { + tagsUpdated = true; + } + } + for (const auto &[roomid, room] : rooms.leave) { + (void)room; + if (spaceOrder_.contains(QString::fromStdString(roomid))) + tagsUpdated = true; } if (tagsUpdated) diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index 0d9ec66b..e4014333 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -85,8 +85,9 @@ RoomlistModel::data(const QModelIndex &index, int role) const case Roles::NotificationCount: return room->notificationCount(); case Roles::IsInvite: - case Roles::IsSpace: return false; + case Roles::IsSpace: + return room->isSpace(); case Roles::Tags: { auto info = cache::singleRoomInfo(roomid.toStdString()); QStringList list; @@ -429,7 +430,9 @@ enum NotificationImportance : short AllEventsRead = 0, NewMessage = 1, NewMentions = 2, - Invite = 3 + Invite = 3, + SubSpace = 4, + CurrentSpace = 5, }; } @@ -439,7 +442,13 @@ FilteredRoomlistModel::calculateImportance(const QModelIndex &idx) const // Returns the degree of importance of the unread messages in the room. // If sorting by importance is disabled in settings, this only ever // returns ImportanceDisabled or Invite - if (sourceModel()->data(idx, RoomlistModel::IsInvite).toBool()) { + if (sourceModel()->data(idx, RoomlistModel::IsSpace).toBool()) { + if (filterType == FilterBy::Space && + filterStr == sourceModel()->data(idx, RoomlistModel::RoomId).toString()) + return CurrentSpace; + else + return SubSpace; + } else if (sourceModel()->data(idx, RoomlistModel::IsInvite).toBool()) { return Invite; } else if (!this->sortByImportance) { return ImportanceDisabled; @@ -539,6 +548,10 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons for (const auto &t : parents) if (hiddenSpaces.contains(t)) return false; + } else if (sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::IsSpace) + .toBool()) { + return false; } return true; @@ -561,6 +574,10 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons for (const auto &t : parents) if (hiddenSpaces.contains(t)) return false; + } else if (sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::IsSpace) + .toBool()) { + return false; } return true; } else if (filterType == FilterBy::Space) { @@ -572,7 +589,11 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags) .toStringList(); - if (!parents.contains(filterStr)) + if (filterStr == sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::RoomId) + .toString()) + return true; + else if (!parents.contains(filterStr)) return false; else if (!hiddenTags.empty()) { for (const auto &t : tags) @@ -582,6 +603,11 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons for (const auto &t : parents) if (hiddenSpaces.contains(t)) return false; + } else if (sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::IsSpace) + .toBool() && + !parents.contains(filterStr)) { + return false; } return true; } else { diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 99547b15..1ecb6cdf 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -320,6 +320,10 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj { lastMessage_.timestamp = 0; + if (auto create = + cache::client()->getStateEvent(room_id.toStdString())) + this->isSpace_ = create->content.type == mtx::events::state::room_type::space; + connect( this, &TimelineModel::redactionFailed, diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 3ebbe120..42aa136f 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -161,6 +161,7 @@ class TimelineModel : public QAbstractListModel Q_PROPERTY(QString roomName READ roomName NOTIFY roomNameChanged) Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl NOTIFY roomAvatarUrlChanged) Q_PROPERTY(QString roomTopic READ roomTopic NOTIFY roomTopicChanged) + Q_PROPERTY(bool isSpace READ isSpace CONSTANT) Q_PROPERTY(InputBar *input READ input CONSTANT) Q_PROPERTY(Permissions *permissions READ permissions NOTIFY permissionsChanged) @@ -262,6 +263,7 @@ public: RelatedInfo relatedInfo(QString id); DescInfo lastMessage() const { return lastMessage_; } + bool isSpace() const { return isSpace_; } public slots: void setCurrentIndex(int index); @@ -366,9 +368,6 @@ private: QString room_id_; - bool decryptDescription = true; - bool m_paginationInProgress = false; - QString currentId, currentReadId; QString reply_, edit_; QString textBeforeEdit, replyBeforeEdit; @@ -388,6 +387,10 @@ private: friend struct SendMessageVisitor; int notification_count = 0, highlight_count = 0; + + bool decryptDescription = true; + bool m_paginationInProgress = false; + bool isSpace_ = false; }; template -- cgit 1.5.1 From c69d2ef64886ee4946abf4b959d53b884014ce7a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 18 Jun 2021 14:13:01 +0200 Subject: Fix off by 1 in previousRoom condition --- src/timeline/RoomlistModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/timeline/RoomlistModel.cpp') diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index e4014333..a44959fc 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -662,7 +662,7 @@ FilteredRoomlistModel::previousRoom() if (r) { int idx = roomidToIndex(r->roomId()); idx--; - if (idx > 0) { + if (idx >= 0) { setCurrentRoom( data(index(idx, 0), RoomlistModel::Roles::RoomId).toString()); } -- cgit 1.5.1 From f8dfc726255df415aaeb9339b20f83cd265ee303 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 20 Jun 2021 13:30:35 +0200 Subject: Fix spaces showing up with world filter --- src/timeline/RoomlistModel.cpp | 69 +++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 25 deletions(-) (limited to 'src/timeline/RoomlistModel.cpp') diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index a44959fc..7f59b112 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -531,6 +531,12 @@ bool FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) const { if (filterType == FilterBy::Nothing) { + if (sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::IsSpace) + .toBool()) { + return false; + } + if (!hiddenTags.empty()) { auto tags = sourceModel() @@ -540,7 +546,9 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons for (const auto &t : tags) if (hiddenTags.contains(t)) return false; - } else if (!hiddenSpaces.empty()) { + } + + if (!hiddenSpaces.empty()) { auto parents = sourceModel() ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::ParentSpaces) @@ -548,25 +556,30 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons for (const auto &t : parents) if (hiddenSpaces.contains(t)) return false; - } else if (sourceModel() - ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::IsSpace) - .toBool()) { - return false; } return true; } else if (filterType == FilterBy::Tag) { + if (sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::IsSpace) + .toBool()) { + return false; + } + auto tags = sourceModel() ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags) .toStringList(); if (!tags.contains(filterStr)) return false; - else if (!hiddenTags.empty()) { + + if (!hiddenTags.empty()) { for (const auto &t : tags) if (t != filterStr && hiddenTags.contains(t)) return false; - } else if (!hiddenSpaces.empty()) { + } + + if (!hiddenSpaces.empty()) { auto parents = sourceModel() ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::ParentSpaces) @@ -574,41 +587,47 @@ FilteredRoomlistModel::filterAcceptsRow(int sourceRow, const QModelIndex &) cons for (const auto &t : parents) if (hiddenSpaces.contains(t)) return false; - } else if (sourceModel() - ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::IsSpace) - .toBool()) { - return false; } + return true; } else if (filterType == FilterBy::Space) { + if (filterStr == sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::RoomId) + .toString()) + return true; + auto parents = sourceModel() ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::ParentSpaces) .toStringList(); - auto tags = sourceModel() - ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags) - .toStringList(); - if (filterStr == sourceModel() - ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::RoomId) - .toString()) - return true; - else if (!parents.contains(filterStr)) + if (!parents.contains(filterStr)) return false; - else if (!hiddenTags.empty()) { + + if (!hiddenTags.empty()) { + auto tags = + sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::Tags) + .toStringList(); + for (const auto &t : tags) if (hiddenTags.contains(t)) return false; - } else if (!hiddenSpaces.empty()) { + } + + if (!hiddenSpaces.empty()) { for (const auto &t : parents) if (hiddenSpaces.contains(t)) return false; - } else if (sourceModel() - ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::IsSpace) - .toBool() && - !parents.contains(filterStr)) { + } + + if (sourceModel() + ->data(sourceModel()->index(sourceRow, 0), RoomlistModel::IsSpace) + .toBool() && + !parents.contains(filterStr)) { return false; } + return true; } else { return true; -- cgit 1.5.1