replacing boolean constants with an improved function name + doc around why the events can be missing

This commit is contained in:
Adam Brown 2021-10-01 16:20:42 +01:00
parent f9d2f236a4
commit c72f66871f
1 changed files with 8 additions and 12 deletions

View File

@ -23,9 +23,6 @@ import org.matrix.android.sdk.internal.database.model.ReadMarkerEntity
import org.matrix.android.sdk.internal.database.model.ReadReceiptEntity import org.matrix.android.sdk.internal.database.model.ReadReceiptEntity
import org.matrix.android.sdk.internal.database.model.TimelineEventEntity import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
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?,
@ -42,7 +39,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 -> handleMissingEvent( eventToCheck == null -> hasReadMissingEvent(
realm = realm, realm = realm,
latestChunkEntity = liveChunk, latestChunkEntity = liveChunk,
roomId = roomId, roomId = roomId,
@ -61,13 +58,12 @@ 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)) { * Missing events can be caused by the latest timeline chunk no longer contain an older event or
MARK_OLD_EVENT_AS_READ * by fast lane eagerly displaying events before the database has finished updating
} else { */
// This can happen when fast lane events are displayed before the database finishes updating private fun hasReadMissingEvent(realm: Realm, latestChunkEntity: ChunkEntity, roomId: String, userId: String, eventId: String): Boolean {
MARK_UNREAD_DUE_TO_FASTLANE return realm.doesEventExistInChunkHistory(eventId) && realm.hasReadReceiptInLatestChunk(latestChunkEntity, roomId, userId)
}
} }
private fun Realm.doesEventExistInChunkHistory(eventId: String): Boolean { private fun Realm.doesEventExistInChunkHistory(eventId: String): Boolean {