Timeline : check isUnlinked before and after merge

This commit is contained in:
ganfra 2018-12-11 15:35:46 +01:00
parent 0611661c46
commit 683305030a
2 changed files with 12 additions and 7 deletions

View File

@ -5,6 +5,7 @@
<w>coroutine</w> <w>coroutine</w>
<w>merlins</w> <w>merlins</w>
<w>moshi</w> <w>moshi</w>
<w>persistor</w>
<w>synchronizer</w> <w>synchronizer</w>
<w>untimelined</w> <w>untimelined</w>
</words> </words>

View File

@ -2,7 +2,12 @@ package im.vector.matrix.android.internal.session.room.timeline


import arrow.core.Try import arrow.core.Try
import com.zhuinden.monarchy.Monarchy 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.ChunkEntity
import im.vector.matrix.android.internal.database.model.RoomEntity import im.vector.matrix.android.internal.database.model.RoomEntity
import im.vector.matrix.android.internal.database.query.create import im.vector.matrix.android.internal.database.query.create
@ -21,7 +26,7 @@ internal class TokenChunkEventPersistor(private val monarchy: Monarchy) {
return monarchy return monarchy
.tryTransactionSync { realm -> .tryTransactionSync { realm ->
val roomEntity = RoomEntity.where(realm, roomId).findFirst() 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 nextToken: String?
val prevToken: String? val prevToken: String?
@ -41,14 +46,13 @@ internal class TokenChunkEventPersistor(private val monarchy: Monarchy) {


var currentChunk = if (direction == PaginationDirection.FORWARDS) { var currentChunk = if (direction == PaginationDirection.FORWARDS) {
prevChunk?.apply { this.nextToken = nextToken } prevChunk?.apply { this.nextToken = nextToken }
?: ChunkEntity.create(realm, prevToken, nextToken) ?: ChunkEntity.create(realm, prevToken, nextToken)
} else { } else {
nextChunk?.apply { this.prevToken = prevToken } 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 = currentChunk.isUnlinked())
currentChunk.addAll(receivedChunk.events, direction, isUnlinked = isUnlinked)


// Then we merge chunks if needed // Then we merge chunks if needed
if (currentChunk != prevChunk && prevChunk != null) { if (currentChunk != prevChunk && prevChunk != null) {
@ -65,7 +69,7 @@ internal class TokenChunkEventPersistor(private val monarchy: Monarchy) {
} }
} }
roomEntity.addOrUpdate(currentChunk) roomEntity.addOrUpdate(currentChunk)
roomEntity.addStateEvents(receivedChunk.stateEvents, isUnlinked = isUnlinked) roomEntity.addStateEvents(receivedChunk.stateEvents, isUnlinked = currentChunk.isUnlinked())
} }
} }