From 92c1bc944d0ae5b9d615b4579b15af86fadfd640 Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Wed, 9 Mar 2022 20:03:42 +0200 Subject: [PATCH] Fix realm crash on v1.4.4 --- .../room/timeline/SendingEventsDataSource.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/SendingEventsDataSource.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/SendingEventsDataSource.kt index b7a2cf2fce..1262c09d97 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/SendingEventsDataSource.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/SendingEventsDataSource.kt @@ -66,7 +66,9 @@ internal class RealmSendingEventsDataSource( private fun updateFrozenResults(sendingEvents: RealmList?) { // Makes sure to close the previous frozen realm - frozenSendingTimelineEvents?.realm?.close() + if (frozenSendingTimelineEvents?.isValid == true) { + frozenSendingTimelineEvents?.realm?.close() + } frozenSendingTimelineEvents = sendingEvents?.freeze() } @@ -74,13 +76,15 @@ internal class RealmSendingEventsDataSource( val builtSendingEvents = mutableListOf() uiEchoManager.getInMemorySendingEvents() .addWithUiEcho(builtSendingEvents) - frozenSendingTimelineEvents - ?.filter { timelineEvent -> - builtSendingEvents.none { it.eventId == timelineEvent.eventId } - } - ?.map { - timelineEventMapper.map(it) - }?.addWithUiEcho(builtSendingEvents) + if (frozenSendingTimelineEvents?.isValid == true) { + frozenSendingTimelineEvents + ?.filter { timelineEvent -> + builtSendingEvents.none { it.eventId == timelineEvent.eventId } + } + ?.map { + timelineEventMapper.map(it) + }?.addWithUiEcho(builtSendingEvents) + } return builtSendingEvents }