mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 10:25:51 +03:00
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:
parent
e0f29a85bb
commit
3214c782bc
2 changed files with 12 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue