Make rooms in the room list bold when there's unread messages

This used to be a feature but kinda broke/changed when we switched to
focusing on context-aware or notable events. Basically instead of only
notable events making a room bold in the room list, it's any unread
messages now.
This commit is contained in:
Joshua Goins
2025-09-09 11:43:25 +02:00
parent f53d47fa28
commit 5b4d3df6ee
5 changed files with 20 additions and 8 deletions

View File

@@ -119,7 +119,7 @@ void RoomListModel::connectRoomSignals(NeoChatRoom *room)
refresh(room, {DisplayNameRole});
});
connect(room, &Room::unreadStatsChanged, this, [this, room] {
refresh(room, {ContextNotificationCountRole, HasHighlightNotificationsRole});
refresh(room, {ContextNotificationCountRole, HasHighlightNotificationsRole, NotificationCountRole});
});
connect(room, &Room::notificationCountChanged, this, [this, room] {
refresh(room);
@@ -271,6 +271,9 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
if (role == IsDirectChat) {
return room->isDirectChat();
}
if (role == NotificationCountRole) {
return room->notificationCount();
}
return QVariant();
}
@@ -304,6 +307,7 @@ QHash<int, QByteArray> RoomListModel::roleNames() const
roles[RoomIdRole] = "roomId";
roles[IsChildSpaceRole] = "isChildSpace";
roles[IsDirectChat] = "isDirectChat";
roles[NotificationCountRole] = "notificationCount";
return roles;
}

View File

@@ -53,6 +53,7 @@ public:
IsChildSpaceRole, /**< Whether this space is a child of a different space. */
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. */
};
Q_ENUM(EventRoles)

View File

@@ -21,6 +21,7 @@ Delegates.RoundedItemDelegate {
required property url avatar
required property string subtitleText
required property string displayName
required property int notificationCount
property bool openOnClick: true
property bool openOnDrag: false
@@ -28,7 +29,8 @@ Delegates.RoundedItemDelegate {
property bool collapsed: false
readonly property bool hasNotifications: contextNotificationCount > 0
readonly property bool hasNotableNotifications: contextNotificationCount > 0
readonly property bool hasUnreadMessages: notificationCount > 0
dropAreaHovered: dropArea.containsDrag
@@ -86,7 +88,7 @@ Delegates.RoundedItemDelegate {
notificationCount: root.contextNotificationCount
notificationHighlight: root.hasHighlightNotifications
showNotificationLabel: root.hasNotifications && root.collapsed
showNotificationLabel: root.hasNotableNotifications && root.collapsed
asynchronous: true
Layout.preferredWidth: height
@@ -104,7 +106,7 @@ Delegates.RoundedItemDelegate {
text: root.displayName
elide: Text.ElideRight
font.weight: root.hasNotifications ? Font.Bold : Font.Normal
font.weight: root.hasUnreadMessages ? Font.Bold : Font.Normal
textFormat: Text.PlainText
Layout.fillWidth: true
@@ -117,7 +119,7 @@ Delegates.RoundedItemDelegate {
text: root.subtitleText
elide: Text.ElideRight
font: Kirigami.Theme.smallFont
opacity: root.hasNotifications ? 0.9 : 0.7
opacity: root.hasUnreadMessages ? 0.9 : 0.7
visible: !NeoChatConfig.compactRoomList && text.length > 0
textFormat: Text.PlainText
@@ -140,12 +142,12 @@ Delegates.RoundedItemDelegate {
id: notificationCountLabel
text: root.contextNotificationCount
visible: root.hasNotifications && !root.collapsed
visible: root.hasNotableNotifications && !root.collapsed
color: Kirigami.Theme.textColor
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
background: Rectangle {
visible: root.hasNotifications
visible: root.hasNotableNotifications
Kirigami.Theme.colorSet: Kirigami.Theme.Button
Kirigami.Theme.inherit: false
color: root.hasHighlightNotifications > 0 ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.backgroundColor

View File

@@ -171,7 +171,7 @@ void RoomTreeModel::connectRoomSignals(NeoChatRoom *room)
refreshRoomRoles(room, {DisplayNameRole});
});
connect(room, &Room::unreadStatsChanged, this, [this, room] {
refreshRoomRoles(room, {ContextNotificationCountRole, HasHighlightNotificationsRole});
refreshRoomRoles(room, {ContextNotificationCountRole, HasHighlightNotificationsRole, NotificationCountRole});
if (room->isServerNoticeRoom()) {
Q_EMIT invalidateSort();
}
@@ -294,6 +294,7 @@ QHash<int, QByteArray> RoomTreeModel::roleNames() const
roles[DelegateTypeRole] = "delegateType";
roles[IconRole] = "icon";
roles[RoomTypeRole] = "roomType";
roles[NotificationCountRole] = "notificationCount";
return roles;
}
@@ -396,6 +397,9 @@ QVariant RoomTreeModel::data(const QModelIndex &index, int role) const
return room->creation()->contentPart<QString>("type"_L1);
}
}
if (role == NotificationCountRole) {
return room->notificationCount();
}
return {};
}

View File

@@ -47,6 +47,7 @@ public:
DelegateTypeRole,
IconRole,
RoomTypeRole, /**< The room's type. */
NotificationCountRole, /**< Count of all notifications that also include non-notable events like unread messages. */
};
Q_ENUM(EventRoles)
explicit RoomTreeModel(QObject *parent = nullptr);