From 30fec15c2018ecb41eb9ccb08fa3422550cdff5a Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Tue, 9 Nov 2021 10:48:07 +0100 Subject: [PATCH] Fix a case where a space could show one unread, but all chats are read Change-Id: I8a0cd85ebd994c22914d3e9a3708ce835c5c7a11 --- .../android/sdk/api/session/room/model/RoomSummary.kt | 11 +++++------ .../sdk/internal/database/model/RoomSummaryEntity.kt | 10 ++++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt index a2bde42585..887cd7d909 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/RoomSummary.kt @@ -75,14 +75,13 @@ data class RoomSummary( val flattenParentIds: List = emptyList() ) { + // Keep in sync with RoomSummaryEntity.kt! val safeUnreadCount: Int get() { - return if (unreadCount != null && unreadCount > 0) { - unreadCount - } else if (hasUnreadOriginalContentMessages) { - 1 - } else { - 0 + return when { + unreadCount != null && unreadCount > 0 -> unreadCount + hasUnreadOriginalContentMessages && roomType != RoomType.SPACE -> 1 + else -> 0 } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt index a1571a1a2f..49e2873509 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/RoomSummaryEntity.kt @@ -26,6 +26,7 @@ import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.RoomJoinRules import org.matrix.android.sdk.api.session.room.model.RoomSummary +import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.room.model.VersioningState import org.matrix.android.sdk.api.session.room.model.tag.RoomTag import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent @@ -125,12 +126,13 @@ internal open class RoomSummaryEntity( } */ + // Keep in sync with RoomSummary.kt! fun safeUnreadCount(): Int { val safeUnreadCount = unreadCount - return if (safeUnreadCount == null || safeUnreadCount <= 0) { - if (hasUnreadOriginalContentMessages) 1 else 0 - } else { - safeUnreadCount + return when { + safeUnreadCount != null && safeUnreadCount > 0 -> safeUnreadCount + hasUnreadOriginalContentMessages && roomType != RoomType.SPACE -> 1 + else -> 0 } }