Sender name: fix for not synced events.

This commit is contained in:
ganfra 2019-07-01 13:20:03 +02:00
parent e838794587
commit d643abbb22
4 changed files with 18 additions and 22 deletions

View File

@ -54,12 +54,10 @@ internal fun RoomEntity.addStateEvents(stateEvents: List<Event>,
}
}
internal fun RoomEntity.addSendingEvent(event: Event,
stateIndex: Int) {
internal fun RoomEntity.addSendingEvent(event: Event) {
assertIsManaged()
val eventEntity = event.toEntity(roomId).apply {
this.sendState = SendState.UNSENT
this.stateIndex = stateIndex
}
sendingTimelineEvents.add(0, eventEntity)
}

View File

@ -19,6 +19,7 @@ package im.vector.matrix.android.internal.session.room.membership
import im.vector.matrix.android.api.session.events.model.EventType
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.RoomMember
import im.vector.matrix.android.api.session.room.send.SendState
import im.vector.matrix.android.internal.database.mapper.ContentMapper
import im.vector.matrix.android.internal.database.model.ChunkEntity
import im.vector.matrix.android.internal.database.model.EventEntity
@ -31,7 +32,6 @@ import im.vector.matrix.android.internal.database.query.where
import io.realm.Realm
import io.realm.RealmList
import io.realm.RealmQuery
import timber.log.Timber
import javax.inject.Inject
internal class SenderRoomMemberExtractor @Inject constructor(private val roomId: String) {
@ -41,16 +41,21 @@ internal class SenderRoomMemberExtractor @Inject constructor(private val roomId:
// If the event is unlinked we want to fetch unlinked state events
val unlinked = event.isUnlinked
val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst() ?: return null
val chunkEntity = ChunkEntity.findIncludingEvent(realm, event.eventId)
val content = when {
chunkEntity == null -> null
event.stateIndex <= 0 -> baseQuery(chunkEntity.events, sender, unlinked).next(from = event.stateIndex)?.prevContent
else -> baseQuery(chunkEntity.events, sender, unlinked).prev(since = event.stateIndex)?.content
}
val fallbackContent = content
?: baseQuery(roomEntity.untimelinedStateEvents, sender, unlinked).prev(since = event.stateIndex)?.content
return ContentMapper.map(fallbackContent).toModel()
// When not synced, we should grab the live RoomMember event
return if (event.sendState != SendState.SYNCED) {
RoomMembers(realm, roomId).get(sender)
} else {
val chunkEntity = ChunkEntity.findIncludingEvent(realm, event.eventId)
val content = when {
chunkEntity == null -> null
event.stateIndex <= 0 -> baseQuery(chunkEntity.events, sender, unlinked).next(from = event.stateIndex)?.prevContent
else -> baseQuery(chunkEntity.events, sender, unlinked).prev(since = event.stateIndex)?.content
}
val fallbackContent = content
?: baseQuery(roomEntity.untimelinedStateEvents, sender, unlinked).prev(since = event.stateIndex)?.content
ContentMapper.map(fallbackContent).toModel()
}
}
private fun baseQuery(list: RealmList<EventEntity>,

View File

@ -176,10 +176,7 @@ internal class DefaultRelationService @Inject constructor(private val context: C
monarchy.tryTransactionAsync { realm ->
val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst()
?: return@tryTransactionAsync
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId = roomId)
?: return@tryTransactionAsync
roomEntity.addSendingEvent(event, liveChunk.forwardsStateIndex ?: 0)
roomEntity.addSendingEvent(event)
}
}
}

View File

@ -33,7 +33,6 @@ 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.findLastLiveChunkFromRoom
import im.vector.matrix.android.internal.database.query.where
import im.vector.matrix.android.internal.session.SessionScope
import im.vector.matrix.android.internal.session.content.ThumbnailExtractor
import im.vector.matrix.android.internal.util.StringProvider
import im.vector.matrix.android.internal.util.tryTransactionAsync
@ -346,10 +345,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
monarchy.tryTransactionAsync { realm ->
val roomEntity = RoomEntity.where(realm, roomId = event.roomId!!).findFirst()
?: return@tryTransactionAsync
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId = event.roomId)
?: return@tryTransactionAsync
roomEntity.addSendingEvent(event, liveChunk.forwardsStateIndex ?: 0)
roomEntity.addSendingEvent(event)
}
}