Fix clearing unread counts if the read receipt was only implicitely set

1. Open room with notifications without reading
2. Send a message
3. Try to mark as read

Before: didn't work, as the read receipt was internally already correct
After: works, since we force set it either way if we see unread counts
Change-Id: I68b20dd0242ea59f454dfbeeabfb58178e4a8395
This commit is contained in:
SpiritCroc 2022-11-10 10:34:20 +01:00
parent e0f29a85bb
commit 3214c782bc
2 changed files with 12 additions and 2 deletions

View file

@ -33,7 +33,8 @@ internal fun isEventRead(
roomId: String?,
eventId: String?,
eventTs: Long? = null,
ignoreSenderId: Boolean = false
ignoreSenderId: Boolean = false,
handleAsUnreadForNonZeroUnreadCount: Boolean = false
): Boolean {
if (userId.isNullOrBlank() || roomId.isNullOrBlank() || eventId.isNullOrBlank()) {
return false
@ -43,6 +44,15 @@ internal fun isEventRead(
}
return Realm.getInstance(realmConfiguration).use { realm ->
// For SetReadMarkersTask, in case the message is somehow still marked as unread even though the receipt is on bottom,
// we want to handle it as if it where unread.
// This scenario can happen after sending a message, but not updating the read receipt manually.
if (handleAsUnreadForNonZeroUnreadCount) {
val roomSummary = RoomSummaryEntity.where(realm, roomId).findFirst()
if (roomSummary?.hasUnreadMessages.orFalse()) {
return false
}
}
val eventToCheck = TimelineEventEntity.where(realm, roomId, eventId).findFirst()
when {
// The event doesn't exist locally, let's assume it hasn't been read unless we know all unread events

View file

@ -92,7 +92,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
rmDimber.i { "Did not set to $fullyReadEventId" }
}
if (readReceiptEventId != null &&
!isEventRead(monarchy.realmConfiguration, userId, params.roomId, readReceiptEventId, ignoreSenderId = true)) {
!isEventRead(monarchy.realmConfiguration, userId, params.roomId, readReceiptEventId, ignoreSenderId = true, handleAsUnreadForNonZeroUnreadCount = true)) {
if (LocalEcho.isLocalEchoId(readReceiptEventId)) {
Timber.w("Can't set read receipt for local event $readReceiptEventId")
} else {