fix Realm crash

This commit is contained in:
ariskotsomitopoulos 2022-03-03 19:10:40 +02:00
parent 39bd437f75
commit daafddbe71

View file

@ -66,12 +66,9 @@ internal class RealmSendingEventsDataSource(
private fun updateFrozenResults(sendingEvents: RealmList<TimelineEventEntity>?) {
// Makes sure to close the previous frozen realm
// TODO find a better way to avoid thread timeline crash:
// - Make RealmSendingEventsDataSource Singleton
// - Do not initialize RealmSendingEventsDataSource when we are in a thread timeline while
// we already have an instance from the main timeline
// - Close Main timeline before Opening a thread timeline
// frozenSendingTimelineEvents?.realm?.close()
if (frozenSendingTimelineEvents?.isValid == true) {
frozenSendingTimelineEvents?.realm?.close()
}
frozenSendingTimelineEvents = sendingEvents?.freeze()
}
@ -79,6 +76,7 @@ internal class RealmSendingEventsDataSource(
val builtSendingEvents = mutableListOf<TimelineEvent>()
uiEchoManager.getInMemorySendingEvents()
.addWithUiEcho(builtSendingEvents)
if (frozenSendingTimelineEvents?.isValid == true) {
frozenSendingTimelineEvents
?.filter { timelineEvent ->
builtSendingEvents.none { it.eventId == timelineEvent.eventId }
@ -86,6 +84,7 @@ internal class RealmSendingEventsDataSource(
?.map {
timelineEventMapper.map(it)
}?.addWithUiEcho(builtSendingEvents)
}
return builtSendingEvents
}