forked from GitHub-Mirror/riotX-android
RoomMembers: should fix state events issues
This commit is contained in:
parent
9182f2ce4e
commit
d469299f42
@ -74,7 +74,7 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(private val roomAP
|
|||||||
|
|
||||||
for (roomMemberEvent in response.roomMemberEvents) {
|
for (roomMemberEvent in response.roomMemberEvents) {
|
||||||
roomEntity.addStateEvent(roomMemberEvent)
|
roomEntity.addStateEvent(roomMemberEvent)
|
||||||
UserEntityFactory.create(roomMemberEvent)?.also {
|
UserEntityFactory.createOrNull(roomMemberEvent)?.also {
|
||||||
realm.insertOrUpdate(it)
|
realm.insertOrUpdate(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ internal class TokenChunkEventPersistor @Inject constructor(private val monarchy
|
|||||||
for (event in receivedChunk.events) {
|
for (event in receivedChunk.events) {
|
||||||
event.eventId?.also { eventIds.add(it) }
|
event.eventId?.also { eventIds.add(it) }
|
||||||
currentChunk.add(roomId, event, direction, isUnlinked = currentChunk.isUnlinked())
|
currentChunk.add(roomId, event, direction, isUnlinked = currentChunk.isUnlinked())
|
||||||
UserEntityFactory.create(event)?.also {
|
UserEntityFactory.createOrNull(event)?.also {
|
||||||
realm.insertOrUpdate(it)
|
realm.insertOrUpdate(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,7 +174,7 @@ internal class TokenChunkEventPersistor @Inject constructor(private val monarchy
|
|||||||
roomEntity.addOrUpdate(currentChunk)
|
roomEntity.addOrUpdate(currentChunk)
|
||||||
for (stateEvent in receivedChunk.stateEvents) {
|
for (stateEvent in receivedChunk.stateEvents) {
|
||||||
roomEntity.addStateEvent(stateEvent, isUnlinked = currentChunk.isUnlinked())
|
roomEntity.addStateEvent(stateEvent, isUnlinked = currentChunk.isUnlinked())
|
||||||
UserEntityFactory.create(stateEvent)?.also {
|
UserEntityFactory.createOrNull(stateEvent)?.also {
|
||||||
realm.insertOrUpdate(it)
|
realm.insertOrUpdate(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import im.vector.matrix.android.api.session.room.model.tag.RoomTagContent
|
|||||||
import im.vector.matrix.android.internal.crypto.CryptoManager
|
import im.vector.matrix.android.internal.crypto.CryptoManager
|
||||||
import im.vector.matrix.android.internal.database.helper.*
|
import im.vector.matrix.android.internal.database.helper.*
|
||||||
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.EventEntityFields
|
||||||
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.model.UserEntity
|
import im.vector.matrix.android.internal.database.model.UserEntity
|
||||||
import im.vector.matrix.android.internal.database.query.find
|
import im.vector.matrix.android.internal.database.query.find
|
||||||
@ -124,34 +125,29 @@ internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarch
|
|||||||
}
|
}
|
||||||
roomEntity.membership = Membership.JOIN
|
roomEntity.membership = Membership.JOIN
|
||||||
|
|
||||||
val lastChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId)
|
|
||||||
val isInitialSync = lastChunk == null
|
|
||||||
val lastStateIndex = lastChunk?.lastStateIndex(PaginationDirection.FORWARDS) ?: 0
|
|
||||||
val numberOfStateEvents = roomSync.state?.events?.size ?: 0
|
|
||||||
val stateIndexOffset = lastStateIndex + numberOfStateEvents
|
|
||||||
|
|
||||||
// State event
|
// State event
|
||||||
if (roomSync.state != null && roomSync.state.events.isNotEmpty()) {
|
if (roomSync.state != null && roomSync.state.events.isNotEmpty()) {
|
||||||
val untimelinedStateIndex = if (isInitialSync) Int.MIN_VALUE else stateIndexOffset
|
val minStateIndex = roomEntity.untimelinedStateEvents.where().min(EventEntityFields.STATE_INDEX)?.toInt()
|
||||||
|
?: Int.MIN_VALUE
|
||||||
|
val untimelinedStateIndex = minStateIndex + 1
|
||||||
roomSync.state.events.forEach { event ->
|
roomSync.state.events.forEach { event ->
|
||||||
roomEntity.addStateEvent(event, filterDuplicates = true, stateIndex = untimelinedStateIndex)
|
roomEntity.addStateEvent(event, filterDuplicates = true, stateIndex = untimelinedStateIndex)
|
||||||
// Give info to crypto module
|
// Give info to crypto module
|
||||||
cryptoManager.onStateEvent(roomId, event)
|
cryptoManager.onStateEvent(roomId, event)
|
||||||
UserEntityFactory.create(event)?.also {
|
UserEntityFactory.createOrNull(event)?.also {
|
||||||
realm.insertOrUpdate(it)
|
realm.insertOrUpdate(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roomSync.timeline != null && roomSync.timeline.events.isNotEmpty()) {
|
if (roomSync.timeline != null && roomSync.timeline.events.isNotEmpty()) {
|
||||||
val timelineStateOffset = if (isInitialSync || roomSync.timeline.limited.not()) 0 else stateIndexOffset
|
|
||||||
val chunkEntity = handleTimelineEvents(
|
val chunkEntity = handleTimelineEvents(
|
||||||
realm,
|
realm,
|
||||||
roomEntity,
|
roomEntity,
|
||||||
roomSync.timeline.events,
|
roomSync.timeline.events,
|
||||||
roomSync.timeline.prevToken,
|
roomSync.timeline.prevToken,
|
||||||
roomSync.timeline.limited,
|
roomSync.timeline.limited,
|
||||||
timelineStateOffset
|
0
|
||||||
)
|
)
|
||||||
roomEntity.addOrUpdate(chunkEntity)
|
roomEntity.addOrUpdate(chunkEntity)
|
||||||
}
|
}
|
||||||
@ -227,7 +223,7 @@ internal class RoomSyncHandler @Inject constructor(private val monarchy: Monarch
|
|||||||
Timber.v("Can't find corresponding local echo for tx:$it")
|
Timber.v("Can't find corresponding local echo for tx:$it")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UserEntityFactory.create(event)?.also {
|
UserEntityFactory.createOrNull(event)?.also {
|
||||||
realm.insertOrUpdate(it)
|
realm.insertOrUpdate(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import im.vector.matrix.android.internal.database.model.UserEntity
|
|||||||
|
|
||||||
internal object UserEntityFactory {
|
internal object UserEntityFactory {
|
||||||
|
|
||||||
fun create(event: Event): UserEntity? {
|
fun createOrNull(event: Event): UserEntity? {
|
||||||
if (event.type != EventType.STATE_ROOM_MEMBER) {
|
if (event.type != EventType.STATE_ROOM_MEMBER) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user