mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-07 06:23:55 +01: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
@ -33,7 +33,8 @@ internal fun isEventRead(
|
|||||||
roomId: String?,
|
roomId: String?,
|
||||||
eventId: String?,
|
eventId: String?,
|
||||||
eventTs: Long? = null,
|
eventTs: Long? = null,
|
||||||
ignoreSenderId: Boolean = false
|
ignoreSenderId: Boolean = false,
|
||||||
|
handleAsUnreadForNonZeroUnreadCount: Boolean = false
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (userId.isNullOrBlank() || roomId.isNullOrBlank() || eventId.isNullOrBlank()) {
|
if (userId.isNullOrBlank() || roomId.isNullOrBlank() || eventId.isNullOrBlank()) {
|
||||||
return false
|
return false
|
||||||
@ -43,6 +44,15 @@ internal fun isEventRead(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Realm.getInstance(realmConfiguration).use { realm ->
|
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()
|
val eventToCheck = TimelineEventEntity.where(realm, roomId, eventId).findFirst()
|
||||||
when {
|
when {
|
||||||
// The event doesn't exist locally, let's assume it hasn't been read unless we know all unread events
|
// 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" }
|
rmDimber.i { "Did not set to $fullyReadEventId" }
|
||||||
}
|
}
|
||||||
if (readReceiptEventId != null &&
|
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)) {
|
if (LocalEcho.isLocalEchoId(readReceiptEventId)) {
|
||||||
Timber.w("Can't set read receipt for local event $readReceiptEventId")
|
Timber.w("Can't set read receipt for local event $readReceiptEventId")
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user