mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 01:15:54 +03:00
After jump to unread, newer messages are never loaded (#1008)
This commit is contained in:
parent
f3c3c07d46
commit
86fba28313
4 changed files with 38 additions and 3 deletions
|
@ -8,7 +8,7 @@ Improvements 🙌:
|
|||
-
|
||||
|
||||
Bugfix 🐛:
|
||||
-
|
||||
- After jump to unread, newer messages are never loaded (#1008)
|
||||
|
||||
Translations 🗣:
|
||||
-
|
||||
|
|
|
@ -34,6 +34,9 @@ internal open class ChunkEntity(@Index var prevToken: String? = null,
|
|||
|
||||
fun identifier() = "${prevToken}_$nextToken"
|
||||
|
||||
// If true, then this chunk was previously a last forward chunk
|
||||
fun hasBeenALastForwardChunk() = nextToken == null && !isLastForward
|
||||
|
||||
@LinkingObjects("chunks")
|
||||
val room: RealmResults<RoomEntity>? = null
|
||||
|
||||
|
|
|
@ -559,6 +559,28 @@ internal class DefaultTimeline(
|
|||
.executeBy(taskExecutor)
|
||||
}
|
||||
|
||||
// For debug purpose only
|
||||
private fun dumpAndLogChunks() {
|
||||
val liveChunk = getLiveChunk()
|
||||
Timber.w("Live chunk: $liveChunk")
|
||||
|
||||
Realm.getInstance(realmConfiguration).use { realm ->
|
||||
ChunkEntity.where(realm, roomId).findAll()
|
||||
.also { Timber.w("Found ${it.size} chunks") }
|
||||
.forEach {
|
||||
Timber.w("")
|
||||
Timber.w("ChunkEntity: $it")
|
||||
Timber.w("prevToken: ${it.prevToken}")
|
||||
Timber.w("nextToken: ${it.nextToken}")
|
||||
Timber.w("isLastBackward: ${it.isLastBackward}")
|
||||
Timber.w("isLastForward: ${it.isLastForward}")
|
||||
it.timelineEvents.forEach { tle ->
|
||||
Timber.w(" TLE: ${tle.root?.content}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This has to be called on TimelineThread as it accesses realm live results
|
||||
*/
|
||||
|
@ -569,6 +591,7 @@ internal class DefaultTimeline(
|
|||
|
||||
/**
|
||||
* This has to be called on TimelineThread as it accesses realm live results
|
||||
* Return the current Chunk
|
||||
*/
|
||||
private fun getLiveChunk(): ChunkEntity? {
|
||||
return nonFilteredEvents.firstOrNull()?.chunk?.firstOrNull()
|
||||
|
@ -576,7 +599,7 @@ internal class DefaultTimeline(
|
|||
|
||||
/**
|
||||
* This has to be called on TimelineThread as it accesses realm live results
|
||||
* @return number of items who have been added
|
||||
* @return the number of items who have been added
|
||||
*/
|
||||
private fun buildTimelineEvents(startDisplayIndex: Int?,
|
||||
direction: Timeline.Direction,
|
||||
|
@ -617,6 +640,8 @@ internal class DefaultTimeline(
|
|||
}
|
||||
val time = System.currentTimeMillis() - start
|
||||
Timber.v("Built ${offsetResults.size} items from db in $time ms")
|
||||
// For the case where wo reach the lastForward chunk
|
||||
updateLoadingStates(filteredEvents)
|
||||
return offsetResults.size
|
||||
}
|
||||
|
||||
|
|
|
@ -224,11 +224,18 @@ internal class TokenChunkEventPersistor @Inject constructor(private val monarchy
|
|||
|
||||
currentChunk.addTimelineEvent(roomId, eventEntity, direction, roomMemberContentsByUser)
|
||||
}
|
||||
// Find all the chunks which contain at least one event from the list of eventIds
|
||||
val chunks = ChunkEntity.findAllIncludingEvents(realm, eventIds)
|
||||
Timber.d("Found ${chunks.size} chunks containing at least one of the eventIds")
|
||||
val chunksToDelete = ArrayList<ChunkEntity>()
|
||||
chunks.forEach {
|
||||
if (it != currentChunk) {
|
||||
currentChunk.merge(roomId, it, direction)
|
||||
if (direction == PaginationDirection.FORWARDS && it.hasBeenALastForwardChunk()) {
|
||||
Timber.d("Do not merge $it")
|
||||
} else {
|
||||
Timber.d("Merge $it")
|
||||
currentChunk.merge(roomId, it, direction)
|
||||
}
|
||||
chunksToDelete.add(it)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue