Force passing realm to TimelineEvent factory

This commit is contained in:
Valere 2019-07-01 19:46:18 +02:00
parent 01e3e71f98
commit ca2223f201
4 changed files with 16 additions and 8 deletions

View File

@ -16,21 +16,29 @@

package im.vector.matrix.android.internal.database.mapper

import com.zhuinden.monarchy.Monarchy
import im.vector.matrix.android.api.session.room.model.RoomSummary
import im.vector.matrix.android.api.session.room.model.tag.RoomTag
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.matrix.android.internal.database.model.RoomSummaryEntity
import im.vector.matrix.android.internal.session.room.timeline.TimelineEventFactory
import javax.inject.Inject


internal class RoomSummaryMapper @Inject constructor(private val timelineEventFactory: TimelineEventFactory) {
internal class RoomSummaryMapper @Inject constructor(
private val timelineEventFactory: TimelineEventFactory,
private val monarchy: Monarchy) {

fun map(roomSummaryEntity: RoomSummaryEntity): RoomSummary {
val tags = roomSummaryEntity.tags.map {
RoomTag(it.tagName, it.tagOrder)
}
val latestEvent = roomSummaryEntity.latestEvent?.let {
timelineEventFactory.create(it)
var ev: TimelineEvent? = null
monarchy.doWithRealm { realm ->
ev = timelineEventFactory.create(it, realm)
}
ev
}
return RoomSummary(
roomId = roomSummaryEntity.roomId,

View File

@ -129,7 +129,7 @@ internal class DefaultTimeline(
builtEventsIdMap[eventId]?.let { builtIndex ->
//Update the relation of existing event
builtEvents[builtIndex]?.let { te ->
builtEvents[builtIndex] = timelineEventFactory.create(eventEntity)
builtEvents[builtIndex] = timelineEventFactory.create(eventEntity, eventEntity.realm)
hasChanged = true
}
}
@ -290,7 +290,7 @@ internal class DefaultTimeline(
roomEntity?.sendingTimelineEvents
?.filter { allowedTypes?.contains(it.type) ?: false }
?.forEach {
val timelineEvent = timelineEventFactory.create(it)
val timelineEvent = timelineEventFactory.create(it, it.realm)
sendingEvents.add(timelineEvent)
}
}
@ -418,7 +418,7 @@ internal class DefaultTimeline(
nextDisplayIndex = offsetIndex + 1
}
offsetResults.forEach { eventEntity ->
val timelineEvent = timelineEventFactory.create(eventEntity)
val timelineEvent = timelineEventFactory.create(eventEntity, eventEntity.realm)
val position = if (direction == Timeline.Direction.FORWARDS) 0 else builtEvents.size
builtEvents.add(position, timelineEvent)
//Need to shift :/

View File

@ -60,14 +60,14 @@ internal class DefaultTimelineService @Inject constructor(private val roomId: St
}
val result = MediatorLiveData<TimelineEvent>()
result.addSource(liveEventEntity) { realmResults ->
result.value = realmResults.firstOrNull()?.let { timelineEventFactory.create(it) }
result.value = realmResults.firstOrNull()?.let { timelineEventFactory.create(it, it.realm) }
}

result.addSource(liveAnnotationsEntity) {
liveEventEntity.value?.let {
result.value = liveEventEntity.value?.let { realmResults ->
//recreate the timeline event
realmResults.firstOrNull()?.let { timelineEventFactory.create(it) }
realmResults.firstOrNull()?.let { timelineEventFactory.create(it, it.realm) }
}
}
}

View File

@ -34,7 +34,7 @@ import java.util.*
import javax.inject.Inject

internal interface TimelineEventFactory {
fun create(eventEntity: EventEntity, realm: Realm = eventEntity.realm): TimelineEvent
fun create(eventEntity: EventEntity, realm: Realm): TimelineEvent
}

internal interface CacheableTimelineEventFactory : TimelineEventFactory {