mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Merge pull request #4129 from vector-im/feature/adm/sync-read-notifications
Fixing notifications not being dismissed when read from other devices
This commit is contained in:
commit
2366227133
2 changed files with 29 additions and 11 deletions
1
changelog.d/3347.bugfix
Normal file
1
changelog.d/3347.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fixes notifications not dismissing when reading messages on other devices
|
|
@ -39,19 +39,18 @@ internal fun isEventRead(realmConfiguration: RealmConfiguration,
|
|||
val liveChunk = ChunkEntity.findLastForwardChunkOfRoom(realm, roomId) ?: return@use
|
||||
val eventToCheck = liveChunk.timelineEvents.find(eventId)
|
||||
isEventRead = when {
|
||||
eventToCheck == null -> {
|
||||
// This can happen in case of fast lane Event
|
||||
false
|
||||
}
|
||||
eventToCheck == null -> hasReadMissingEvent(
|
||||
realm = realm,
|
||||
latestChunkEntity = liveChunk,
|
||||
roomId = roomId,
|
||||
userId = userId,
|
||||
eventId = eventId
|
||||
)
|
||||
eventToCheck.root?.sender == userId -> true
|
||||
else -> {
|
||||
val readReceipt = ReadReceiptEntity.where(realm, roomId, userId).findFirst()
|
||||
?: return@use
|
||||
val readReceiptIndex = liveChunk.timelineEvents.find(readReceipt.eventId)?.displayIndex
|
||||
?: Int.MIN_VALUE
|
||||
val eventToCheckIndex = eventToCheck.displayIndex
|
||||
|
||||
eventToCheckIndex <= readReceiptIndex
|
||||
val readReceipt = ReadReceiptEntity.where(realm, roomId, userId).findFirst() ?: return@use
|
||||
val readReceiptIndex = liveChunk.timelineEvents.find(readReceipt.eventId)?.displayIndex ?: Int.MIN_VALUE
|
||||
eventToCheck.displayIndex <= readReceiptIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +58,24 @@ internal fun isEventRead(realmConfiguration: RealmConfiguration,
|
|||
return isEventRead
|
||||
}
|
||||
|
||||
/**
|
||||
* Missing events can be caused by the latest timeline chunk no longer contain an older event or
|
||||
* by fast lane eagerly displaying events before the database has finished updating
|
||||
*/
|
||||
private fun hasReadMissingEvent(realm: Realm, latestChunkEntity: ChunkEntity, roomId: String, userId: String, eventId: String): Boolean {
|
||||
return realm.doesEventExistInChunkHistory(eventId) && realm.hasReadReceiptInLatestChunk(latestChunkEntity, roomId, userId)
|
||||
}
|
||||
|
||||
private fun Realm.doesEventExistInChunkHistory(eventId: String): Boolean {
|
||||
return ChunkEntity.findIncludingEvent(this, eventId) != null
|
||||
}
|
||||
|
||||
private fun Realm.hasReadReceiptInLatestChunk(latestChunkEntity: ChunkEntity, roomId: String, userId: String): Boolean {
|
||||
return ReadReceiptEntity.where(this, roomId = roomId, userId = userId).findFirst()?.let {
|
||||
latestChunkEntity.timelineEvents.find(it.eventId)
|
||||
} != null
|
||||
}
|
||||
|
||||
internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration,
|
||||
roomId: String?,
|
||||
eventId: String?): Boolean {
|
||||
|
|
Loading…
Reference in a new issue