Use writeAsync for localEcho

This commit is contained in:
ganfra 2020-07-03 21:12:27 +02:00
parent 283f32479d
commit 7434aed43f
2 changed files with 4 additions and 7 deletions

View file

@ -62,7 +62,6 @@ import im.vector.matrix.android.internal.session.content.ThumbnailExtractor
import im.vector.matrix.android.internal.session.room.send.pills.TextPillsUtils import im.vector.matrix.android.internal.session.room.send.pills.TextPillsUtils
import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.task.TaskExecutor
import im.vector.matrix.android.internal.util.StringProvider import im.vector.matrix.android.internal.util.StringProvider
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
/** /**
@ -474,9 +473,7 @@ internal class LocalEchoEventFactory @Inject constructor(
fun createLocalEcho(event: Event) { fun createLocalEcho(event: Event) {
checkNotNull(event.roomId) { "Your event should have a roomId" } checkNotNull(event.roomId) { "Your event should have a roomId" }
taskExecutor.executorScope.launch { localEchoRepository.createLocalEcho(event)
localEchoRepository.createLocalEcho(event)
}
} }
companion object { companion object {

View file

@ -48,7 +48,7 @@ internal class LocalEchoRepository @Inject constructor(@SessionDatabase private
private val eventBus: EventBus, private val eventBus: EventBus,
private val timelineEventMapper: TimelineEventMapper) { private val timelineEventMapper: TimelineEventMapper) {
suspend fun createLocalEcho(event: Event) { fun createLocalEcho(event: Event) {
val roomId = event.roomId ?: throw IllegalStateException("You should have set a roomId for your event") val roomId = event.roomId ?: throw IllegalStateException("You should have set a roomId for your event")
val senderId = event.senderId ?: throw IllegalStateException("You should have set a senderIf for your event") val senderId = event.senderId ?: throw IllegalStateException("You should have set a senderIf for your event")
if (event.eventId == null) { if (event.eventId == null) {
@ -70,8 +70,8 @@ internal class LocalEchoRepository @Inject constructor(@SessionDatabase private
} }
val timelineEvent = timelineEventMapper.map(timelineEventEntity) val timelineEvent = timelineEventMapper.map(timelineEventEntity)
eventBus.post(DefaultTimeline.OnLocalEchoCreated(roomId = roomId, timelineEvent = timelineEvent)) eventBus.post(DefaultTimeline.OnLocalEchoCreated(roomId = roomId, timelineEvent = timelineEvent))
monarchy.awaitTransaction { realm -> monarchy.writeAsync { realm ->
val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst() ?: return@awaitTransaction val roomEntity = RoomEntity.where(realm, roomId = roomId).findFirst() ?: return@writeAsync
roomEntity.sendingTimelineEvents.add(0, timelineEventEntity) roomEntity.sendingTimelineEvents.add(0, timelineEventEntity)
roomSummaryUpdater.update(realm, roomId) roomSummaryUpdater.update(realm, roomId)
} }