mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
fix Realm crash
This commit is contained in:
parent
39bd437f75
commit
daafddbe71
1 changed files with 12 additions and 13 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue