Fix unread indicator for messages (#7841)

* The expected logic for unread messages is displaying just a dot

The count might not be accurate, so we keep the dot for now.

* Fix tests
This commit is contained in:
Jorge Martin Espinosa
2026-10-02 16:36:22 +02:00
committed by GitHub
parent d826a72d49
commit 7fd8e5b721
2 changed files with 7 additions and 10 deletions
@@ -391,14 +391,11 @@ internal fun RoomListRoomSummary.unreadIndicatorCount(
val isMuted = userDefinedNotificationMode == RoomNotificationMode.MUTE val isMuted = userDefinedNotificationMode == RoomNotificationMode.MUTE
return when { return when {
// Show only unread notifications when the room is not muted and there are unread notifications // Show only unread notifications when the room is not muted and there are unread notifications
!isMuted && numberOfUnreadNotifications > 0 -> numberOfUnreadNotifications !isMuted && numberOfUnreadNotifications > 0 -> if (showUnreadCount) numberOfUnreadNotifications else 0
// Otherwise, show unread messages when showAllActivity is true // Otherwise, show a dot for unread messages when showAllActivity is true and there are unread messages
showAllActivity -> numberOfUnreadMessages.takeIf { it > 0 } showAllActivity -> if (numberOfUnreadMessages > 0) 0 else null
// Or don't display anything // Or don't display anything
else -> null else -> null
}?.let {
// We only want to show the count if the option is enabled, otherwise we just show the dot indicator (value 0)
if (showUnreadCount) it else 0
} }
} }
@@ -34,12 +34,12 @@ class RoomSummaryRowUnreadIndicatorCountTest {
} }
@Test @Test
fun `unread messages are used when there are no unread notifications and showAllActivity is true`() { fun `unread messages are used when there are no unread notifications and showAllActivity is true, but always display a dot`() {
val room = createRoomListRoomSummary( val room = createRoomListRoomSummary(
numberOfUnreadNotifications = 0, numberOfUnreadNotifications = 0,
numberOfUnreadMessages = 5, numberOfUnreadMessages = 5,
) )
assertThat(room.unreadIndicatorCount(showUnreadCount = true, showAllActivity = true)).isEqualTo(5L) assertThat(room.unreadIndicatorCount(showUnreadCount = true, showAllActivity = true)).isEqualTo(0L)
assertThat(room.unreadIndicatorCount(showUnreadCount = false, showAllActivity = true)).isEqualTo(0L) assertThat(room.unreadIndicatorCount(showUnreadCount = false, showAllActivity = true)).isEqualTo(0L)
} }
@@ -54,13 +54,13 @@ class RoomSummaryRowUnreadIndicatorCountTest {
} }
@Test @Test
fun `muted room ignores unread notifications and falls back to unread messages when showAllActivity is true`() { fun `muted room ignores unread notifications and falls back to unread messages displaying a dot when showAllActivity is true`() {
val room = createRoomListRoomSummary( val room = createRoomListRoomSummary(
numberOfUnreadNotifications = 3, numberOfUnreadNotifications = 3,
numberOfUnreadMessages = 5, numberOfUnreadMessages = 5,
userDefinedNotificationMode = RoomNotificationMode.MUTE, userDefinedNotificationMode = RoomNotificationMode.MUTE,
) )
assertThat(room.unreadIndicatorCount(showUnreadCount = true, showAllActivity = true)).isEqualTo(5L) assertThat(room.unreadIndicatorCount(showUnreadCount = true, showAllActivity = true)).isEqualTo(0L)
assertThat(room.unreadIndicatorCount(showUnreadCount = false, showAllActivity = true)).isEqualTo(0L) assertThat(room.unreadIndicatorCount(showUnreadCount = false, showAllActivity = true)).isEqualTo(0L)
assertThat(room.unreadIndicatorCount(showUnreadCount = true, showAllActivity = false)).isNull() assertThat(room.unreadIndicatorCount(showUnreadCount = true, showAllActivity = false)).isNull()
} }