forked from GitHub-Mirror/riotX-android
Room state: fix sync state events duplicates with timeline
This commit is contained in:
parent
40f1fcab18
commit
f59977f884
@ -21,6 +21,7 @@ import im.vector.matrix.android.internal.database.mapper.toEntity
|
||||
import im.vector.matrix.android.internal.database.mapper.updateWith
|
||||
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.fastContains
|
||||
|
||||
|
||||
internal fun RoomEntity.deleteOnCascade(chunkEntity: ChunkEntity) {
|
||||
@ -37,16 +38,17 @@ internal fun RoomEntity.addOrUpdate(chunkEntity: ChunkEntity) {
|
||||
|
||||
internal fun RoomEntity.addStateEvents(stateEvents: List<Event>,
|
||||
stateIndex: Int = Int.MIN_VALUE,
|
||||
filterDuplicates: Boolean = false,
|
||||
isUnlinked: Boolean = false) {
|
||||
if (!isManaged) {
|
||||
throw IllegalStateException("Chunk entity should be managed to use fast contains")
|
||||
}
|
||||
stateEvents.forEach { event ->
|
||||
if (event.eventId == null) {
|
||||
if (event.eventId == null || (filterDuplicates && fastContains(event.eventId))) {
|
||||
return@forEach
|
||||
}
|
||||
val eventEntity = event.toEntity(roomId)
|
||||
eventEntity.updateWith(stateIndex, isUnlinked)
|
||||
untimelinedStateEvents.add(eventEntity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package im.vector.matrix.android.internal.database.query
|
||||
|
||||
import im.vector.matrix.android.api.session.room.model.MyMembership
|
||||
import im.vector.matrix.android.internal.database.model.EventEntity
|
||||
import im.vector.matrix.android.internal.database.model.RoomEntity
|
||||
import im.vector.matrix.android.internal.database.model.RoomEntityFields
|
||||
import io.realm.Realm
|
||||
@ -34,3 +35,7 @@ internal fun RoomEntity.Companion.where(realm: Realm, membership: MyMembership?
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
internal fun RoomEntity.fastContains(eventId: String): Boolean {
|
||||
return EventEntity.where(realm, eventId = eventId).findFirst() != null
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ internal class RoomSyncHandler(private val monarchy: Monarchy,
|
||||
|
||||
if (roomSync.state != null && roomSync.state.events.isNotEmpty()) {
|
||||
val untimelinedStateIndex = if (isInitialSync) Int.MIN_VALUE else stateIndexOffset
|
||||
roomEntity.addStateEvents(roomSync.state.events, stateIndex = untimelinedStateIndex)
|
||||
roomEntity.addStateEvents(roomSync.state.events, filterDuplicates = true, stateIndex = untimelinedStateIndex)
|
||||
}
|
||||
|
||||
if (roomSync.timeline != null && roomSync.timeline.events.isNotEmpty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user