mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 19:05:56 +03:00
Fix endless loading timeline due to conflicting chunks
This commit is contained in:
parent
17d363cf9a
commit
682f4c35d2
3 changed files with 33 additions and 1 deletions
1
changelog.d/5554.bugfix
Normal file
1
changelog.d/5554.bugfix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix sometimes endless loading timeline
|
|
@ -40,6 +40,17 @@ internal fun ChunkEntity.Companion.find(realm: Realm, roomId: String, prevToken:
|
||||||
return query.findFirst()
|
return query.findFirst()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun ChunkEntity.Companion.findAll(realm: Realm, roomId: String, prevToken: String? = null, nextToken: String? = null): RealmResults<ChunkEntity>? {
|
||||||
|
val query = where(realm, roomId)
|
||||||
|
if (prevToken != null) {
|
||||||
|
query.equalTo(ChunkEntityFields.PREV_TOKEN, prevToken)
|
||||||
|
}
|
||||||
|
if (nextToken != null) {
|
||||||
|
query.equalTo(ChunkEntityFields.NEXT_TOKEN, nextToken)
|
||||||
|
}
|
||||||
|
return query.findAll()
|
||||||
|
}
|
||||||
|
|
||||||
internal fun ChunkEntity.Companion.findLastForwardChunkOfRoom(realm: Realm, roomId: String): ChunkEntity? {
|
internal fun ChunkEntity.Companion.findLastForwardChunkOfRoom(realm: Realm, roomId: String): ChunkEntity? {
|
||||||
return where(realm, roomId)
|
return where(realm, roomId)
|
||||||
.equalTo(ChunkEntityFields.IS_LAST_FORWARD, true)
|
.equalTo(ChunkEntityFields.IS_LAST_FORWARD, true)
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.matrix.android.sdk.internal.database.model.TimelineEventEntityFields
|
||||||
import org.matrix.android.sdk.internal.database.query.copyToRealmOrIgnore
|
import org.matrix.android.sdk.internal.database.query.copyToRealmOrIgnore
|
||||||
import org.matrix.android.sdk.internal.database.query.create
|
import org.matrix.android.sdk.internal.database.query.create
|
||||||
import org.matrix.android.sdk.internal.database.query.find
|
import org.matrix.android.sdk.internal.database.query.find
|
||||||
|
import org.matrix.android.sdk.internal.database.query.findAll
|
||||||
import org.matrix.android.sdk.internal.database.query.where
|
import org.matrix.android.sdk.internal.database.query.where
|
||||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||||
import org.matrix.android.sdk.internal.di.UserId
|
import org.matrix.android.sdk.internal.di.UserId
|
||||||
|
@ -80,7 +81,26 @@ internal class TokenChunkEventPersistor @Inject constructor(
|
||||||
|
|
||||||
val existingChunk = ChunkEntity.find(realm, roomId, prevToken = prevToken, nextToken = nextToken)
|
val existingChunk = ChunkEntity.find(realm, roomId, prevToken = prevToken, nextToken = nextToken)
|
||||||
if (existingChunk != null) {
|
if (existingChunk != null) {
|
||||||
Timber.v("This chunk is already in the db, returns")
|
Timber.v("This chunk is already in the db, checking if this might be caused by broken links")
|
||||||
|
if (direction == PaginationDirection.FORWARDS) {
|
||||||
|
val prevChunks = ChunkEntity.findAll(realm, roomId, nextToken = prevToken)
|
||||||
|
Timber.v("Found ${prevChunks?.size} prevChunks")
|
||||||
|
prevChunks?.forEach {
|
||||||
|
if (it.nextChunk != existingChunk) {
|
||||||
|
Timber.i("Set nextChunk for ${it.identifier()} from ${it.nextChunk?.identifier()} to ${existingChunk.identifier()}")
|
||||||
|
it.nextChunk = existingChunk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val nextChunks = ChunkEntity.findAll(realm, roomId, prevToken = nextToken)
|
||||||
|
Timber.v("Found ${nextChunks?.size} nextChunks")
|
||||||
|
nextChunks?.forEach {
|
||||||
|
if (it.prevChunk != existingChunk) {
|
||||||
|
Timber.i("Set prevChunk for ${it.identifier()} from ${it.prevChunk?.identifier()} to ${existingChunk.identifier()}")
|
||||||
|
it.prevChunk = existingChunk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return@awaitTransaction
|
return@awaitTransaction
|
||||||
}
|
}
|
||||||
val prevChunk = ChunkEntity.find(realm, roomId, nextToken = prevToken)
|
val prevChunk = ChunkEntity.find(realm, roomId, nextToken = prevToken)
|
||||||
|
|
Loading…
Reference in a new issue