diff --git a/.idea/dictionaries/ganfra.xml b/.idea/dictionaries/ganfra.xml
index 1ca7a97a77..7e1fdcddbb 100644
--- a/.idea/dictionaries/ganfra.xml
+++ b/.idea/dictionaries/ganfra.xml
@@ -5,6 +5,7 @@
coroutine
merlins
moshi
+ persistor
synchronizer
untimelined
diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TokenChunkEventPersistor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TokenChunkEventPersistor.kt
index 4e74496963..bf4e9b490e 100644
--- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TokenChunkEventPersistor.kt
+++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/timeline/TokenChunkEventPersistor.kt
@@ -2,7 +2,12 @@ package im.vector.matrix.android.internal.session.room.timeline
import arrow.core.Try
import com.zhuinden.monarchy.Monarchy
-import im.vector.matrix.android.internal.database.helper.*
+import im.vector.matrix.android.internal.database.helper.addAll
+import im.vector.matrix.android.internal.database.helper.addOrUpdate
+import im.vector.matrix.android.internal.database.helper.addStateEvents
+import im.vector.matrix.android.internal.database.helper.deleteOnCascade
+import im.vector.matrix.android.internal.database.helper.isUnlinked
+import im.vector.matrix.android.internal.database.helper.merge
import im.vector.matrix.android.internal.database.model.ChunkEntity
import im.vector.matrix.android.internal.database.model.RoomEntity
import im.vector.matrix.android.internal.database.query.create
@@ -21,7 +26,7 @@ internal class TokenChunkEventPersistor(private val monarchy: Monarchy) {
return monarchy
.tryTransactionSync { realm ->
val roomEntity = RoomEntity.where(realm, roomId).findFirst()
- ?: throw IllegalStateException("You shouldn't use this method without a room")
+ ?: throw IllegalStateException("You shouldn't use this method without a room")
val nextToken: String?
val prevToken: String?
@@ -41,14 +46,13 @@ internal class TokenChunkEventPersistor(private val monarchy: Monarchy) {
var currentChunk = if (direction == PaginationDirection.FORWARDS) {
prevChunk?.apply { this.nextToken = nextToken }
- ?: ChunkEntity.create(realm, prevToken, nextToken)
+ ?: ChunkEntity.create(realm, prevToken, nextToken)
} else {
nextChunk?.apply { this.prevToken = prevToken }
- ?: ChunkEntity.create(realm, prevToken, nextToken)
+ ?: ChunkEntity.create(realm, prevToken, nextToken)
}
- val isUnlinked = currentChunk.isUnlinked()
- currentChunk.addAll(receivedChunk.events, direction, isUnlinked = isUnlinked)
+ currentChunk.addAll(receivedChunk.events, direction, isUnlinked = currentChunk.isUnlinked())
// Then we merge chunks if needed
if (currentChunk != prevChunk && prevChunk != null) {
@@ -65,7 +69,7 @@ internal class TokenChunkEventPersistor(private val monarchy: Monarchy) {
}
}
roomEntity.addOrUpdate(currentChunk)
- roomEntity.addStateEvents(receivedChunk.stateEvents, isUnlinked = isUnlinked)
+ roomEntity.addStateEvents(receivedChunk.stateEvents, isUnlinked = currentChunk.isUnlinked())
}
}