mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
EventEntity|TimelineEventEntity : remove UUID as primary key and use auto-incremented Long
This commit is contained in:
parent
f007fb04b8
commit
1b95336ad3
@ -28,7 +28,7 @@ import im.vector.matrix.android.api.session.room.send.SendState
|
|||||||
*/
|
*/
|
||||||
data class TimelineEvent(
|
data class TimelineEvent(
|
||||||
val root: Event,
|
val root: Event,
|
||||||
val localId: String,
|
val localId: Long,
|
||||||
val displayIndex: Int,
|
val displayIndex: Int,
|
||||||
val senderName: String?,
|
val senderName: String?,
|
||||||
val isUniqueDisplayName: Boolean,
|
val isUniqueDisplayName: Boolean,
|
||||||
|
@ -134,7 +134,8 @@ internal fun ChunkEntity.add(roomId: String,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val eventEntity = TimelineEventEntity().also {
|
val localId = TimelineEventEntity.nextId(realm)
|
||||||
|
val eventEntity = TimelineEventEntity(localId).also {
|
||||||
it.root = event.toEntity(roomId).apply {
|
it.root = event.toEntity(roomId).apply {
|
||||||
this.stateIndex = currentStateIndex
|
this.stateIndex = currentStateIndex
|
||||||
this.isUnlinked = isUnlinked
|
this.isUnlinked = isUnlinked
|
||||||
|
@ -26,7 +26,6 @@ import im.vector.matrix.android.internal.database.query.fastContains
|
|||||||
import im.vector.matrix.android.internal.extensions.assertIsManaged
|
import im.vector.matrix.android.internal.extensions.assertIsManaged
|
||||||
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
||||||
|
|
||||||
|
|
||||||
internal fun RoomEntity.deleteOnCascade(chunkEntity: ChunkEntity) {
|
internal fun RoomEntity.deleteOnCascade(chunkEntity: ChunkEntity) {
|
||||||
chunks.remove(chunkEntity)
|
chunks.remove(chunkEntity)
|
||||||
chunkEntity.deleteOnCascade()
|
chunkEntity.deleteOnCascade()
|
||||||
@ -65,7 +64,8 @@ internal fun RoomEntity.addSendingEvent(event: Event) {
|
|||||||
}
|
}
|
||||||
val roomMembers = RoomMembers(realm, roomId)
|
val roomMembers = RoomMembers(realm, roomId)
|
||||||
val myUser = roomMembers.get(senderId)
|
val myUser = roomMembers.get(senderId)
|
||||||
val timelineEventEntity = TimelineEventEntity().also {
|
val localId = TimelineEventEntity.nextId(realm)
|
||||||
|
val timelineEventEntity = TimelineEventEntity(localId).also {
|
||||||
it.root = eventEntity
|
it.root = eventEntity
|
||||||
it.eventId = event.eventId ?: ""
|
it.eventId = event.eventId ?: ""
|
||||||
it.roomId = roomId
|
it.roomId = roomId
|
||||||
|
@ -30,9 +30,11 @@ import im.vector.matrix.android.internal.database.query.prev
|
|||||||
import im.vector.matrix.android.internal.database.query.where
|
import im.vector.matrix.android.internal.database.query.where
|
||||||
import im.vector.matrix.android.internal.extensions.assertIsManaged
|
import im.vector.matrix.android.internal.extensions.assertIsManaged
|
||||||
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
import im.vector.matrix.android.internal.session.room.membership.RoomMembers
|
||||||
|
import io.realm.Realm
|
||||||
import io.realm.RealmList
|
import io.realm.RealmList
|
||||||
import io.realm.RealmQuery
|
import io.realm.RealmQuery
|
||||||
|
|
||||||
|
|
||||||
internal fun TimelineEventEntity.updateSenderData() {
|
internal fun TimelineEventEntity.updateSenderData() {
|
||||||
assertIsManaged()
|
assertIsManaged()
|
||||||
val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst() ?: return
|
val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst() ?: return
|
||||||
@ -69,6 +71,15 @@ internal fun TimelineEventEntity.updateSenderData() {
|
|||||||
this.senderMembershipEvent = senderMembershipEvent
|
this.senderMembershipEvent = senderMembershipEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun TimelineEventEntity.Companion.nextId(realm: Realm): Long{
|
||||||
|
val currentIdNum = realm.where(TimelineEventEntity::class.java).max(TimelineEventEntityFields.LOCAL_ID)
|
||||||
|
return if (currentIdNum == null) {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
currentIdNum.toLong() + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun RealmList<TimelineEventEntity>.buildQuery(sender: String, isUnlinked: Boolean): RealmQuery<TimelineEventEntity> {
|
private fun RealmList<TimelineEventEntity>.buildQuery(sender: String, isUnlinked: Boolean): RealmQuery<TimelineEventEntity> {
|
||||||
return where()
|
return where()
|
||||||
.equalTo(TimelineEventEntityFields.ROOT.STATE_KEY, sender)
|
.equalTo(TimelineEventEntityFields.ROOT.STATE_KEY, sender)
|
||||||
|
@ -35,7 +35,7 @@ internal object EventMapper {
|
|||||||
val uds = if (event.unsignedData == null) null
|
val uds = if (event.unsignedData == null) null
|
||||||
else MoshiProvider.providesMoshi().adapter(UnsignedData::class.java).toJson(event.unsignedData)
|
else MoshiProvider.providesMoshi().adapter(UnsignedData::class.java).toJson(event.unsignedData)
|
||||||
val eventEntity = EventEntity()
|
val eventEntity = EventEntity()
|
||||||
eventEntity.eventId = event.eventId ?: UUID.randomUUID().toString()
|
eventEntity.eventId = event.eventId ?: ""
|
||||||
eventEntity.roomId = event.roomId ?: roomId
|
eventEntity.roomId = event.roomId ?: roomId
|
||||||
eventEntity.content = ContentMapper.map(event.content)
|
eventEntity.content = ContentMapper.map(event.content)
|
||||||
val resolvedPrevContent = event.prevContent ?: event.unsignedData?.prevContent
|
val resolvedPrevContent = event.prevContent ?: event.unsignedData?.prevContent
|
||||||
|
@ -23,15 +23,6 @@ import im.vector.matrix.android.internal.database.model.TimelineEventEntity
|
|||||||
|
|
||||||
internal object TimelineEventMapper {
|
internal object TimelineEventMapper {
|
||||||
|
|
||||||
fun map(timelineEvent: TimelineEvent, roomId: String): TimelineEventEntity {
|
|
||||||
val timelineEventEntity = TimelineEventEntity()
|
|
||||||
timelineEventEntity.root = timelineEvent.root.toEntity(roomId)
|
|
||||||
timelineEventEntity.eventId = timelineEvent.root.eventId ?: ""
|
|
||||||
timelineEventEntity.roomId = roomId
|
|
||||||
timelineEventEntity.annotations = timelineEvent.annotations?.let { EventAnnotationsSummaryMapper.map(it, roomId) }
|
|
||||||
return timelineEventEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
fun map(timelineEventEntity: TimelineEventEntity): TimelineEvent {
|
fun map(timelineEventEntity: TimelineEventEntity): TimelineEvent {
|
||||||
|
|
||||||
return TimelineEvent(
|
return TimelineEvent(
|
||||||
@ -53,8 +44,4 @@ internal fun TimelineEventEntity.asDomain(): TimelineEvent {
|
|||||||
return TimelineEventMapper.map(this)
|
return TimelineEventMapper.map(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun TimelineEvent.toEntity(roomId: String): TimelineEventEntity {
|
|
||||||
return TimelineEventMapper.map(this, roomId)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,8 +27,7 @@ import io.realm.annotations.LinkingObjects
|
|||||||
import io.realm.annotations.PrimaryKey
|
import io.realm.annotations.PrimaryKey
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
internal open class EventEntity(@PrimaryKey var localId: String = UUID.randomUUID().toString(),
|
internal open class EventEntity(@Index var eventId: String = "",
|
||||||
@Index var eventId: String = "",
|
|
||||||
@Index var roomId: String = "",
|
@Index var roomId: String = "",
|
||||||
@Index var type: String = "",
|
@Index var type: String = "",
|
||||||
var content: String? = null,
|
var content: String? = null,
|
||||||
|
@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
package im.vector.matrix.android.internal.database.model
|
package im.vector.matrix.android.internal.database.model
|
||||||
|
|
||||||
import com.squareup.moshi.Types
|
|
||||||
import im.vector.matrix.android.internal.crypto.MXEventDecryptionResult
|
|
||||||
import im.vector.matrix.android.internal.database.mapper.ContentMapper
|
|
||||||
import im.vector.matrix.android.internal.di.MoshiProvider
|
|
||||||
import io.realm.RealmObject
|
import io.realm.RealmObject
|
||||||
import io.realm.RealmResults
|
import io.realm.RealmResults
|
||||||
import io.realm.annotations.Index
|
import io.realm.annotations.Index
|
||||||
@ -28,7 +24,7 @@ import io.realm.annotations.PrimaryKey
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
internal open class TimelineEventEntity(@PrimaryKey var localId: String = UUID.randomUUID().toString(),
|
internal open class TimelineEventEntity(var localId: Long = 0,
|
||||||
@Index var eventId: String = "",
|
@Index var eventId: String = "",
|
||||||
@Index var roomId: String = "",
|
@Index var roomId: String = "",
|
||||||
var root: EventEntity? = null,
|
var root: EventEntity? = null,
|
||||||
|
@ -18,6 +18,7 @@ package im.vector.riotx.features.home.room.detail.timeline
|
|||||||
|
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.util.LongSparseArray
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.ListUpdateCallback
|
import androidx.recyclerview.widget.ListUpdateCallback
|
||||||
@ -82,8 +83,8 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Tim
|
|||||||
fun onUrlLongClicked(url: String): Boolean
|
fun onUrlLongClicked(url: String): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
private val collapsedEventIds = linkedSetOf<String>()
|
private val collapsedEventIds = linkedSetOf<Long>()
|
||||||
private val mergeItemCollapseStates = HashMap<String, Boolean>()
|
private val mergeItemCollapseStates = HashMap<Long,Boolean>()
|
||||||
private val modelCache = arrayListOf<CacheItemData?>()
|
private val modelCache = arrayListOf<CacheItemData?>()
|
||||||
|
|
||||||
private var currentSnapshot: List<TimelineEvent> = emptyList()
|
private var currentSnapshot: List<TimelineEvent> = emptyList()
|
||||||
@ -298,7 +299,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Tim
|
|||||||
} else {
|
} else {
|
||||||
collapsedEventIds.removeAll(mergedEventIds)
|
collapsedEventIds.removeAll(mergedEventIds)
|
||||||
}
|
}
|
||||||
val mergeId = mergedEventIds.joinToString(separator = "_") { it }
|
val mergeId = mergedEventIds.joinToString(separator = "_") { it.toString() }
|
||||||
MergedHeaderItem(isCollapsed, mergeId, mergedData, avatarRenderer) {
|
MergedHeaderItem(isCollapsed, mergeId, mergedData, avatarRenderer) {
|
||||||
mergeItemCollapseStates[event.localId] = it
|
mergeItemCollapseStates[event.localId] = it
|
||||||
requestModelBuild()
|
requestModelBuild()
|
||||||
@ -329,7 +330,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Tim
|
|||||||
}
|
}
|
||||||
|
|
||||||
private data class CacheItemData(
|
private data class CacheItemData(
|
||||||
val localId: String,
|
val localId: Long,
|
||||||
val eventId: String?,
|
val eventId: String?,
|
||||||
val eventModel: EpoxyModel<*>? = null,
|
val eventModel: EpoxyModel<*>? = null,
|
||||||
val mergedHeaderModel: MergedHeaderItem? = null,
|
val mergedHeaderModel: MergedHeaderItem? = null,
|
||||||
|
@ -78,7 +78,7 @@ data class MergedHeaderItem(private val isCollapsed: Boolean,
|
|||||||
}
|
}
|
||||||
|
|
||||||
data class Data(
|
data class Data(
|
||||||
val eventId: String,
|
val eventId: Long,
|
||||||
val userId: String,
|
val userId: String,
|
||||||
val memberName: String,
|
val memberName: String,
|
||||||
val avatarUrl: String?
|
val avatarUrl: String?
|
||||||
|
Loading…
Reference in New Issue
Block a user