Rely on MSC2654 unread counts when available for detecting unread status

Previously, we were doing some hybrid approach, in order to take into
account the room preview settings. However, this can mark chats as
unread in cases where isEventRead() does guessing due to insufficient
events loaded. Just using the counts when possible is more reliable.

Change-Id: I22dc242e69f1946c039d0b4f81851c6b0c0556e2
This commit is contained in:
SpiritCroc 2022-05-13 20:41:54 +02:00
parent 200370912a
commit d1ee0dea6b

View file

@ -160,18 +160,26 @@ internal class RoomSummaryUpdater @Inject constructor(
)
}
roomSummaryEntity.hasUnreadMessages = roomSummaryEntity.notificationCount > 0 ||
(roomSummaryEntity.unreadCount?.let { it > 0 } ?: false) ||
// avoid this call if we are sure there are unread events
latestPreviewableEvent?.let { !isEventRead(realm.configuration, userId, roomId, it.eventId) } ?: false
roomSummaryEntity.hasUnreadContentMessages = roomSummaryEntity.notificationCount > 0 ||
(roomSummaryEntity.unreadCount?.let { it > 0 } ?: false) ||
// avoid this call if we are sure there are unread events
latestPreviewableContentEvent?.let { !isEventRead(realm.configuration, userId, roomId, it.eventId) } ?: false
roomSummaryEntity.hasUnreadOriginalContentMessages = roomSummaryEntity.notificationCount > 0 ||
(roomSummaryEntity.unreadCount?.let { it > 0 } ?: false) ||
// avoid this call if we are sure there are unread events
latestPreviewableOriginalContentEvent?.let { !isEventRead(realm.configuration, userId, roomId, it.eventId) } ?: false
val roomSummaryUnreadCount = roomSummaryEntity.unreadCount
if (roomSummaryUnreadCount != null /* && preferences.prioritizeUnreadCountsOverRoomPreviewsForUnreadCalculation() */) {
val hasUnreadMessages = roomSummaryUnreadCount > 0
roomSummaryEntity.hasUnreadMessages = hasUnreadMessages
roomSummaryEntity.hasUnreadContentMessages = hasUnreadMessages
roomSummaryEntity.hasUnreadOriginalContentMessages = hasUnreadMessages
} else {
roomSummaryEntity.hasUnreadMessages = roomSummaryEntity.notificationCount > 0 ||
//(roomSummaryEntity.unreadCount?.let { it > 0 } ?: false) ||
// avoid this call if we are sure there are unread events
latestPreviewableEvent?.let { !isEventRead(realm.configuration, userId, roomId, it.eventId) } ?: false
roomSummaryEntity.hasUnreadContentMessages = roomSummaryEntity.notificationCount > 0 ||
//(roomSummaryEntity.unreadCount?.let { it > 0 } ?: false) ||
// avoid this call if we are sure there are unread events
latestPreviewableContentEvent?.let { !isEventRead(realm.configuration, userId, roomId, it.eventId) } ?: false
roomSummaryEntity.hasUnreadOriginalContentMessages = roomSummaryEntity.notificationCount > 0 ||
//(roomSummaryEntity.unreadCount?.let { it > 0 } ?: false) ||
// avoid this call if we are sure there are unread events
latestPreviewableOriginalContentEvent?.let { !isEventRead(realm.configuration, userId, roomId, it.eventId) } ?: false
}
roomSummaryEntity.setDisplayName(roomDisplayNameResolver.resolve(realm, roomId))
roomSummaryEntity.avatarUrl = roomAvatarResolver.resolve(realm, roomId)