Hide rooms with custom defined types in quick switcher

This matches the behavior in other room lists. I also tried to normalize
the constructor with SortFilterRoomTreeModel.
This commit is contained in:
Joshua Goins
2026-02-10 20:11:48 -05:00
parent 115d4e7466
commit 847db41fb3
3 changed files with 15 additions and 4 deletions

View File

@@ -276,6 +276,11 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
if (role == NotificationCountRole) { if (role == NotificationCountRole) {
return room->notificationCount(); return room->notificationCount();
} }
if (role == RoomTypeRole) {
if (room->creation()) {
return room->creation()->contentPart<QString>("type"_L1);
}
}
return QVariant(); return QVariant();
} }
@@ -310,6 +315,7 @@ QHash<int, QByteArray> RoomListModel::roleNames() const
roles[IsChildSpaceRole] = "isChildSpace"; roles[IsChildSpaceRole] = "isChildSpace";
roles[IsDirectChat] = "isDirectChat"; roles[IsDirectChat] = "isDirectChat";
roles[NotificationCountRole] = "notificationCount"; roles[NotificationCountRole] = "notificationCount";
roles[RoomTypeRole] = "roomType";
return roles; return roles;
} }

View File

@@ -54,6 +54,7 @@ public:
ReplacementIdRole, /**< The room id of the room replacing this one, if any. */ ReplacementIdRole, /**< The room id of the room replacing this one, if any. */
IsDirectChat, /**< Whether this room is a direct chat. */ IsDirectChat, /**< Whether this room is a direct chat. */
NotificationCountRole, /**< Count of all notifications that also include non-notable events like unread messages. */ NotificationCountRole, /**< Count of all notifications that also include non-notable events like unread messages. */
RoomTypeRole, /**< The room's type. */
}; };
Q_ENUM(EventRoles) Q_ENUM(EventRoles)

View File

@@ -3,6 +3,7 @@
#include "sortfilterroomlistmodel.h" #include "sortfilterroomlistmodel.h"
#include "enums/neochatroomtype.h"
#include "neochatconnection.h" #include "neochatconnection.h"
using namespace Qt::StringLiterals; using namespace Qt::StringLiterals;
@@ -14,11 +15,9 @@ SortFilterRoomListModel::SortFilterRoomListModel(RoomListModel *sourceModel, QOb
setSourceModel(sourceModel); setSourceModel(sourceModel);
sort(0); sort(0);
invalidateFilter(); connect(this, &SortFilterRoomListModel::filterTextChanged, this, &SortFilterRoomListModel::invalidateFilter);
connect(this, &SortFilterRoomListModel::filterTextChanged, this, [this]() {
invalidateFilter();
});
connect(this, &SortFilterRoomListModel::sourceModelChanged, this, [this]() { connect(this, &SortFilterRoomListModel::sourceModelChanged, this, [this]() {
this->sourceModel()->disconnect(this);
connect(this->sourceModel(), &QAbstractListModel::rowsInserted, this, &SortFilterRoomListModel::invalidateRowsFilter); connect(this->sourceModel(), &QAbstractListModel::rowsInserted, this, &SortFilterRoomListModel::invalidateRowsFilter);
connect(this->sourceModel(), &QAbstractListModel::rowsRemoved, this, &SortFilterRoomListModel::invalidateRowsFilter); connect(this->sourceModel(), &QAbstractListModel::rowsRemoved, this, &SortFilterRoomListModel::invalidateRowsFilter);
}); });
@@ -44,6 +43,11 @@ bool SortFilterRoomListModel::filterAcceptsRow(int source_row, const QModelIndex
return false; return false;
} }
// Hide rooms with defined types, assuming that data-holding rooms have a defined type
if (!sourceModel()->data(index, RoomListModel::RoomTypeRole).toString().isEmpty()) {
return false;
}
return sourceModel()->data(index, RoomListModel::DisplayNameRole).toString().contains(m_filterText, Qt::CaseInsensitive) return sourceModel()->data(index, RoomListModel::DisplayNameRole).toString().contains(m_filterText, Qt::CaseInsensitive)
&& sourceModel()->data(index, RoomListModel::IsSpaceRole).toBool() == false; && sourceModel()->data(index, RoomListModel::IsSpaceRole).toBool() == false;
} }