Fix readmarker index calculcation if local echos exist

Change-Id: Ia1f0cfb719c2497d4aa840964432e7d39b299d40
This commit is contained in:
SpiritCroc 2022-03-21 15:21:47 +01:00
parent 86c49cba5d
commit d58e9bb944
1 changed files with 4 additions and 1 deletions

View File

@ -90,6 +90,7 @@ internal class LoadTimelineStrategy(
private var getContextLatch: CompletableDeferred<Unit>? = null private var getContextLatch: CompletableDeferred<Unit>? = null
private var chunkEntity: RealmResults<ChunkEntity>? = null private var chunkEntity: RealmResults<ChunkEntity>? = null
private var timelineChunk: TimelineChunk? = null private var timelineChunk: TimelineChunk? = null
private var sendingEventCount: Int = 0
private val chunkEntityListener = OrderedRealmCollectionChangeListener { _: RealmResults<ChunkEntity>, changeSet: OrderedCollectionChangeSet -> private val chunkEntityListener = OrderedRealmCollectionChangeListener { _: RealmResults<ChunkEntity>, changeSet: OrderedCollectionChangeSet ->
// Can be call either when you open a permalink on an unknown event // Can be call either when you open a permalink on an unknown event
@ -189,7 +190,7 @@ internal class LoadTimelineStrategy(
} }
fun getBuiltEventIndex(eventId: String): Int? { fun getBuiltEventIndex(eventId: String): Int? {
return timelineChunk?.getBuiltEventIndex(eventId, searchInNext = true, searchInPrev = true) return timelineChunk?.getBuiltEventIndex(eventId, searchInNext = true, searchInPrev = true)?.let { it + sendingEventCount }
} }
fun getBuiltEvent(eventId: String): TimelineEvent? { fun getBuiltEvent(eventId: String): TimelineEvent? {
@ -205,6 +206,8 @@ internal class LoadTimelineStrategy(
sendingEventsDataSource.buildSendingEvents() sendingEventsDataSource.buildSendingEvents()
} else { } else {
emptyList() emptyList()
}.also {
sendingEventCount = it.size
} }
} }