mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-02 20:26:47 +01:00
fixes notifications not being marked as read when the last chunk containing the event is no longer the latest
- use explict returns constants to attempt to add more documentation - queries for the existence of the event in all of the chunk history and if a read receipt exists in the latest chunk (which it should if a user has just read on another client) which allows us to mark old notifications events as read
This commit is contained in:
parent
5d51431c60
commit
7105a20f4f
@ -23,6 +23,9 @@ import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
|
|||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmConfiguration
|
import io.realm.RealmConfiguration
|
||||||
|
|
||||||
|
private const val MARK_OLD_EVENT_AS_READ = true
|
||||||
|
private const val MARK_UNREAD_DUE_TO_FASTLANE = false
|
||||||
|
|
||||||
internal fun isEventRead(realmConfiguration: RealmConfiguration,
|
internal fun isEventRead(realmConfiguration: RealmConfiguration,
|
||||||
userId: String?,
|
userId: String?,
|
||||||
roomId: String?,
|
roomId: String?,
|
||||||
@ -39,10 +42,7 @@ internal fun isEventRead(realmConfiguration: RealmConfiguration,
|
|||||||
val liveChunk = ChunkEntity.findLastForwardChunkOfRoom(realm, roomId) ?: return@use
|
val liveChunk = ChunkEntity.findLastForwardChunkOfRoom(realm, roomId) ?: return@use
|
||||||
val eventToCheck = liveChunk.timelineEvents.find(eventId)
|
val eventToCheck = liveChunk.timelineEvents.find(eventId)
|
||||||
isEventRead = when {
|
isEventRead = when {
|
||||||
eventToCheck == null -> {
|
eventToCheck == null -> handleMissingEvent(realm, liveChunk, roomId, userId, eventId)
|
||||||
// This can happen in case of fast lane Event
|
|
||||||
false
|
|
||||||
}
|
|
||||||
eventToCheck.root?.sender == userId -> true
|
eventToCheck.root?.sender == userId -> true
|
||||||
else -> {
|
else -> {
|
||||||
val readReceipt = ReadReceiptEntity.where(realm, roomId, userId).findFirst()
|
val readReceipt = ReadReceiptEntity.where(realm, roomId, userId).findFirst()
|
||||||
@ -59,6 +59,26 @@ internal fun isEventRead(realmConfiguration: RealmConfiguration,
|
|||||||
return isEventRead
|
return isEventRead
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleMissingEvent(realm: Realm, latestChunkEntity: ChunkEntity, roomId: String, userId: String, eventId: String): Boolean {
|
||||||
|
return if (realm.doesEventExistInChunkHistory(eventId) && realm.hasReadReceiptInLatestChunk(latestChunkEntity, roomId, userId)) {
|
||||||
|
MARK_OLD_EVENT_AS_READ
|
||||||
|
} else {
|
||||||
|
// This can happen when fast lane events are displayed before the database finishes updating
|
||||||
|
MARK_UNREAD_DUE_TO_FASTLANE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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, userId).findFirst()?.let {
|
||||||
|
latestChunkEntity.timelineEvents.find(it.eventId)
|
||||||
|
} != null
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration,
|
internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration,
|
||||||
roomId: String?,
|
roomId: String?,
|
||||||
eventId: String?): Boolean {
|
eventId: String?): Boolean {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user