From 5b4d3df6ee177c8748d76458d01cbcdb13589390 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 9 Sep 2025 11:43:25 +0200 Subject: [PATCH] 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. --- src/libneochat/models/roomlistmodel.cpp | 6 +++++- src/libneochat/models/roomlistmodel.h | 1 + src/rooms/RoomDelegate.qml | 14 ++++++++------ src/rooms/models/roomtreemodel.cpp | 6 +++++- src/rooms/models/roomtreemodel.h | 1 + 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/libneochat/models/roomlistmodel.cpp b/src/libneochat/models/roomlistmodel.cpp index 648275359..88c0b50ce 100644 --- a/src/libneochat/models/roomlistmodel.cpp +++ b/src/libneochat/models/roomlistmodel.cpp @@ -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 RoomListModel::roleNames() const roles[RoomIdRole] = "roomId"; roles[IsChildSpaceRole] = "isChildSpace"; roles[IsDirectChat] = "isDirectChat"; + roles[NotificationCountRole] = "notificationCount"; return roles; } diff --git a/src/libneochat/models/roomlistmodel.h b/src/libneochat/models/roomlistmodel.h index 6f12f50d1..5b7317ea0 100644 --- a/src/libneochat/models/roomlistmodel.h +++ b/src/libneochat/models/roomlistmodel.h @@ -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) diff --git a/src/rooms/RoomDelegate.qml b/src/rooms/RoomDelegate.qml index 6b9f58b3f..a0fa92d9f 100644 --- a/src/rooms/RoomDelegate.qml +++ b/src/rooms/RoomDelegate.qml @@ -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 diff --git a/src/rooms/models/roomtreemodel.cpp b/src/rooms/models/roomtreemodel.cpp index 124af14bd..105b517e5 100644 --- a/src/rooms/models/roomtreemodel.cpp +++ b/src/rooms/models/roomtreemodel.cpp @@ -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 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("type"_L1); } } + if (role == NotificationCountRole) { + return room->notificationCount(); + } return {}; } diff --git a/src/rooms/models/roomtreemodel.h b/src/rooms/models/roomtreemodel.h index a0bb6d925..6f4034a07 100644 --- a/src/rooms/models/roomtreemodel.h +++ b/src/rooms/models/roomtreemodel.h @@ -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);