From bb9ce117de7d39a278272d6dc8e272f9f63c5c7d Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 9 Nov 2024 16:14:00 -0500 Subject: [PATCH] Hide rooms that have a defined room type I have a room with a custom type that's only for holding data, and doesn't need to be shown in the room list. Currently the spec is a bit vague about what clients should do, but hiding them is probably fine for now. --- src/models/roomtreemodel.cpp | 6 ++++++ src/models/roomtreemodel.h | 1 + src/models/sortfilterroomtreemodel.cpp | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/src/models/roomtreemodel.cpp b/src/models/roomtreemodel.cpp index bfcfcd243..574033e60 100644 --- a/src/models/roomtreemodel.cpp +++ b/src/models/roomtreemodel.cpp @@ -286,6 +286,7 @@ QHash RoomTreeModel::roleNames() const roles[IconRole] = "icon"; roles[AttentionRole] = "attention"; roles[FavouriteRole] = "favourite"; + roles[RoomTypeRole] = "roomType"; return roles; } @@ -385,6 +386,11 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const if (role == FavouriteRole) { return room->isFavourite(); } + if (role == RoomTypeRole) { + if (room->creation()) { + return room->creation()->contentPart("type"_L1); + } + } return {}; } diff --git a/src/models/roomtreemodel.h b/src/models/roomtreemodel.h index 7b2d32eda..326f97359 100644 --- a/src/models/roomtreemodel.h +++ b/src/models/roomtreemodel.h @@ -50,6 +50,7 @@ public: IconRole, AttentionRole, /**< Whether there are any notifications. */ FavouriteRole, /**< Whether the room is favourited. */ + RoomTypeRole, /**< The room's type. */ }; Q_ENUM(EventRoles) explicit RoomTreeModel(QObject *parent = nullptr); diff --git a/src/models/sortfilterroomtreemodel.cpp b/src/models/sortfilterroomtreemodel.cpp index e3c3339d1..f2de87fc6 100644 --- a/src/models/sortfilterroomtreemodel.cpp +++ b/src/models/sortfilterroomtreemodel.cpp @@ -157,6 +157,11 @@ bool SortFilterRoomTreeModel::filterAcceptsRow(int source_row, const QModelIndex return false; } + // Hide rooms with defined types, assuming that data-holding rooms have a defined type + if (!sourceModel()->data(index, RoomTreeModel::RoomTypeRole).toString().isEmpty()) { + return false; + } + static auto config = NeoChatConfig::self(); if (config->allRoomsInHome() && RoomManager::instance().currentSpace().isEmpty()) { return acceptRoom;