mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 17:35:54 +03:00
Introduce a localId for event, to avoid blink effect when sending
This commit is contained in:
parent
0f667fe6e8
commit
4656429d83
4 changed files with 17 additions and 8 deletions
|
@ -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_
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ class TimelineEventController(private val roomId: String,
|
||||||
}
|
}
|
||||||
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) {
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue