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,
|
internal fun RoomEntity.addSendingEvent(event: Event) {
|
||||||
stateIndex: Int) {
|
|
||||||
assertIsManaged()
|
assertIsManaged()
|
||||||
val eventEntity = event.toEntity(roomId).apply {
|
val eventEntity = event.toEntity(roomId).apply {
|
||||||
this.sendState = SendState.UNSENT
|
this.sendState = SendState.UNSENT
|
||||||
this.stateIndex = stateIndex
|
|
||||||
}
|
}
|
||||||
sendingTimelineEvents.add(0, eventEntity)
|
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.EventType
|
||||||
import im.vector.matrix.android.api.session.events.model.toModel
|
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.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.mapper.ContentMapper
|
||||||
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.EventEntity
|
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.Realm
|
||||||
import io.realm.RealmList
|
import io.realm.RealmList
|
||||||
import io.realm.RealmQuery
|
import io.realm.RealmQuery
|
||||||
import timber.log.Timber
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class SenderRoomMemberExtractor @Inject constructor(private val roomId: String) {
|
internal class SenderRoomMemberExtractor @Inject constructor(private val roomId: String) {
|
||||||
|
@ -41,6 +41,11 @@ internal class SenderRoomMemberExtractor @Inject constructor(private val roomId:
|
||||||
// If the event is unlinked we want to fetch unlinked state events
|
// If the event is unlinked we want to fetch unlinked state events
|
||||||
val unlinked = event.isUnlinked
|
val unlinked = event.isUnlinked
|
||||||
val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst() ?: return null
|
val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst() ?: return null
|
||||||
|
|
||||||
|
// 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 chunkEntity = ChunkEntity.findIncludingEvent(realm, event.eventId)
|
||||||
val content = when {
|
val content = when {
|
||||||
chunkEntity == null -> null
|
chunkEntity == null -> null
|
||||||
|
@ -49,8 +54,8 @@ internal class SenderRoomMemberExtractor @Inject constructor(private val roomId:
|
||||||
}
|
}
|
||||||
val fallbackContent = content
|
val fallbackContent = content
|
||||||
?: baseQuery(roomEntity.untimelinedStateEvents, sender, unlinked).prev(since = event.stateIndex)?.content
|
?: baseQuery(roomEntity.untimelinedStateEvents, sender, unlinked).prev(since = event.stateIndex)?.content
|
||||||
|
ContentMapper.map(fallbackContent).toModel()
|
||||||
return ContentMapper.map(fallbackContent).toModel()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun baseQuery(list: RealmList<EventEntity>,
|
private fun baseQuery(list: RealmList<EventEntity>,
|
||||||
|
|
|
@ -176,10 +176,7 @@ internal class DefaultRelationService @Inject constructor(private val context: C
|
||||||
monarchy.tryTransactionAsync { realm ->
|
monarchy.tryTransactionAsync { realm ->
|
||||||
val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst()
|
val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst()
|
||||||
?: return@tryTransactionAsync
|
?: return@tryTransactionAsync
|
||||||
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId = roomId)
|
roomEntity.addSendingEvent(event)
|
||||||
?: return@tryTransactionAsync
|
|
||||||
|
|
||||||
roomEntity.addSendingEvent(event, liveChunk.forwardsStateIndex ?: 0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.model.RoomEntity
|
||||||
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
import im.vector.matrix.android.internal.database.query.findLastLiveChunkFromRoom
|
||||||
import im.vector.matrix.android.internal.database.query.where
|
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.session.content.ThumbnailExtractor
|
||||||
import im.vector.matrix.android.internal.util.StringProvider
|
import im.vector.matrix.android.internal.util.StringProvider
|
||||||
import im.vector.matrix.android.internal.util.tryTransactionAsync
|
import im.vector.matrix.android.internal.util.tryTransactionAsync
|
||||||
|
@ -346,10 +345,7 @@ internal class LocalEchoEventFactory @Inject constructor(private val credentials
|
||||||
monarchy.tryTransactionAsync { realm ->
|
monarchy.tryTransactionAsync { realm ->
|
||||||
val roomEntity = RoomEntity.where(realm, roomId = event.roomId!!).findFirst()
|
val roomEntity = RoomEntity.where(realm, roomId = event.roomId!!).findFirst()
|
||||||
?: return@tryTransactionAsync
|
?: return@tryTransactionAsync
|
||||||
val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(realm, roomId = event.roomId)
|
roomEntity.addSendingEvent(event)
|
||||||
?: return@tryTransactionAsync
|
|
||||||
|
|
||||||
roomEntity.addSendingEvent(event, liveChunk.forwardsStateIndex ?: 0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue