mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 03:48:12 +03:00
Timeline : check isUnlinked before and after merge
This commit is contained in:
parent
0611661c46
commit
683305030a
2 changed files with 12 additions and 7 deletions
|
@ -5,6 +5,7 @@
|
|||
<w>coroutine</w>
|
||||
<w>merlins</w>
|
||||
<w>moshi</w>
|
||||
<w>persistor</w>
|
||||
<w>synchronizer</w>
|
||||
<w>untimelined</w>
|
||||
</words>
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue