diff --git a/src/libneochat/models/roomlistmodel.cpp b/src/libneochat/models/roomlistmodel.cpp index bec0dedd8..8c99a64cb 100644 --- a/src/libneochat/models/roomlistmodel.cpp +++ b/src/libneochat/models/roomlistmodel.cpp @@ -276,6 +276,11 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const if (role == NotificationCountRole) { return room->notificationCount(); } + if (role == RoomTypeRole) { + if (room->creation()) { + return room->creation()->contentPart("type"_L1); + } + } return QVariant(); } @@ -310,6 +315,7 @@ QHash RoomListModel::roleNames() const roles[IsChildSpaceRole] = "isChildSpace"; roles[IsDirectChat] = "isDirectChat"; roles[NotificationCountRole] = "notificationCount"; + roles[RoomTypeRole] = "roomType"; return roles; } diff --git a/src/libneochat/models/roomlistmodel.h b/src/libneochat/models/roomlistmodel.h index 5b7317ea0..735f29ea3 100644 --- a/src/libneochat/models/roomlistmodel.h +++ b/src/libneochat/models/roomlistmodel.h @@ -54,6 +54,7 @@ public: ReplacementIdRole, /**< The room id of the room replacing this one, if any. */ IsDirectChat, /**< Whether this room is a direct chat. */ NotificationCountRole, /**< Count of all notifications that also include non-notable events like unread messages. */ + RoomTypeRole, /**< The room's type. */ }; Q_ENUM(EventRoles) diff --git a/src/rooms/models/sortfilterroomlistmodel.cpp b/src/rooms/models/sortfilterroomlistmodel.cpp index c785e1fb6..1bd657cb3 100644 --- a/src/rooms/models/sortfilterroomlistmodel.cpp +++ b/src/rooms/models/sortfilterroomlistmodel.cpp @@ -3,6 +3,7 @@ #include "sortfilterroomlistmodel.h" +#include "enums/neochatroomtype.h" #include "neochatconnection.h" using namespace Qt::StringLiterals; @@ -14,11 +15,9 @@ SortFilterRoomListModel::SortFilterRoomListModel(RoomListModel *sourceModel, QOb setSourceModel(sourceModel); sort(0); - invalidateFilter(); - connect(this, &SortFilterRoomListModel::filterTextChanged, this, [this]() { - invalidateFilter(); - }); + connect(this, &SortFilterRoomListModel::filterTextChanged, this, &SortFilterRoomListModel::invalidateFilter); connect(this, &SortFilterRoomListModel::sourceModelChanged, this, [this]() { + this->sourceModel()->disconnect(this); connect(this->sourceModel(), &QAbstractListModel::rowsInserted, 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; } + // 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) && sourceModel()->data(index, RoomListModel::IsSpaceRole).toBool() == false; }