Sender name: fix for not synced events.
This commit is contained in:
parent
e838794587
commit
d643abbb22
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue