From 8a1da1c02f6cdec50464a0bb4d67fe59dbe6e87d Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 22 May 2022 13:00:45 +0200 Subject: [PATCH] Avoid mismatch between hasUnread and notificationCount because of unreadCount With MSC2654 unread counts, it is possible such count is zero while the notification count isn't. So also respect the notification count when deciding if a chat has unread messages. Change-Id: I1b9f6ae907eb468c27fc0bb75b711db04268560a --- .../internal/session/room/summary/RoomSummaryUpdater.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt index be46015037..d6a8eec145 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryUpdater.kt @@ -175,7 +175,12 @@ internal class RoomSummaryUpdater @Inject constructor( val roomSummaryUnreadCount = roomSummaryEntity.unreadCount if (roomSummaryUnreadCount != null /* && preferences.prioritizeUnreadCountsOverRoomPreviewsForUnreadCalculation() */) { - val hasUnreadMessages = roomSummaryUnreadCount > 0 + // MSC2654 says: + // In case of a mismatch between this count and the value of notification_count in the Unread Notification Counts section, + // clients should use the unread_count. + // However, we do not do this here: if the notificationCount > 0, this means we likely got a push notification. Accordingly, it would be confusing + // not to show such chat as unread. We can test this e.g. with edits: the unreadCount doesn't count edits, but the notification push rules do. + val hasUnreadMessages = roomSummaryUnreadCount > 0 || roomSummaryEntity.notificationCount > 0 roomSummaryEntity.hasUnreadMessages = hasUnreadMessages roomSummaryEntity.hasUnreadContentMessages = hasUnreadMessages roomSummaryEntity.hasUnreadOriginalContentMessages = hasUnreadMessages