Introduce a localId for event, to avoid blink effect when sending

This commit is contained in:
ganfra 2018-12-17 18:25:02 +01:00
parent 0f667fe6e8
commit 4656429d83
4 changed files with 17 additions and 8 deletions

View file

@ -5,6 +5,7 @@ import com.airbnb.epoxy.EpoxyAsyncUtil
import com.airbnb.epoxy.EpoxyController import com.airbnb.epoxy.EpoxyController
import im.vector.matrix.android.api.session.events.model.EnrichedEvent import im.vector.matrix.android.api.session.events.model.EnrichedEvent
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.localId
import im.vector.riotredesign.core.extensions.localDateTime import im.vector.riotredesign.core.extensions.localDateTime
import im.vector.riotredesign.features.home.LoadingItemModel_ import im.vector.riotredesign.features.home.LoadingItemModel_
@ -62,11 +63,11 @@ class TimelineEventController(private val roomId: String,
val item = when (event.root.type) { val item = when (event.root.type) {
EventType.MESSAGE -> messageItemFactory.create(event, nextEvent, addDaySeparator, date) EventType.MESSAGE -> messageItemFactory.create(event, nextEvent, addDaySeparator, date)
else -> textItemFactory.create(event) else -> textItemFactory.create(event)
} }
item item
?.onBind { timeline?.loadAround(index) } ?.onBind { timeline?.loadAround(index) }
?.id(event.root.eventId) ?.id(event.localId())
?.addTo(this) ?.addTo(this)
if (addDaySeparator) { if (addDaySeparator) {

View file

@ -20,12 +20,18 @@ data class EnrichedEvent(val root: Event) {
} }
companion object { companion object {
const val ROOM_MEMBER = "ROOM_MEMBER"
const val IS_LAST_EVENT = "IS_LAST_EVENT" const val IS_LAST_EVENT = "IS_LAST_EVENT"
const val READ_RECEIPTS = "READ_RECEIPTS" const val READ_RECEIPTS = "READ_RECEIPTS"
const val LOCAL_ID = "LOCAL_ID"
} }
} }
fun EnrichedEvent.roomMember(): RoomMember? { fun EnrichedEvent.roomMember(): RoomMember? {
return getMetadata<RoomMember>(EventType.STATE_ROOM_MEMBER) return getMetadata<RoomMember>(EnrichedEvent.ROOM_MEMBER)
}
fun EnrichedEvent.localId(): String? {
return getMetadata<String>(EnrichedEvent.LOCAL_ID)
} }

View file

@ -3,8 +3,11 @@ package im.vector.matrix.android.internal.database.model
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.RealmResults import io.realm.RealmResults
import io.realm.annotations.LinkingObjects import io.realm.annotations.LinkingObjects
import io.realm.annotations.PrimaryKey
import java.util.*
internal open class EventEntity(var eventId: String = "", internal open class EventEntity(@PrimaryKey var localId: String = UUID.randomUUID().toString(),
var eventId: String = "",
var type: String = "", var type: String = "",
var content: String = "", var content: String = "",
var prevContent: String? = null, var prevContent: String? = null,

View file

@ -18,16 +18,15 @@ internal class MessageEventInterceptor(private val monarchy: Monarchy,
override fun enrich(event: EnrichedEvent) { override fun enrich(event: EnrichedEvent) {
monarchy.doWithRealm { realm -> monarchy.doWithRealm { realm ->
if (event.root.eventId == null) { if (event.root.eventId == null) {
return@doWithRealm return@doWithRealm
} }
val rootEntity = EventEntity.where(realm, eventId = event.root.eventId).findFirst() val rootEntity = EventEntity.where(realm, eventId = event.root.eventId).findFirst()
?: return@doWithRealm ?: return@doWithRealm
event.enrichWith(EnrichedEvent.LOCAL_ID, rootEntity.localId)
val roomMember = RoomMemberExtractor(realm, roomId).extractFrom(rootEntity) val roomMember = RoomMemberExtractor(realm, roomId).extractFrom(rootEntity)
event.enrichWith(EventType.STATE_ROOM_MEMBER, roomMember) event.enrichWith(EnrichedEvent.ROOM_MEMBER, roomMember)
} }
} }