From 37dc77cc3ea9e1feefa4b989e18b434aeca21dcd Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Tue, 5 Apr 2022 20:36:33 +0300 Subject: [PATCH] Add isValid check to RealmChangeListener to prevent crashes on deleted objects --- .../session/room/timeline/SendingEventsDataSource.kt | 8 +++++--- .../app/features/home/room/detail/TimelineFragment.kt | 1 - 2 files changed, 5 insertions(+), 4 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 cb61222de7..637267a9b1 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 @@ -45,9 +45,11 @@ internal class RealmSendingEventsDataSource( private var frozenSendingTimelineEvents: RealmList? = null private val sendingTimelineEventsListener = RealmChangeListener> { events -> - uiEchoManager.onSentEventsInDatabase(events.map { it.eventId }) - updateFrozenResults(events) - onEventsUpdated(false) + if (events.isValid) { + uiEchoManager.onSentEventsInDatabase(events.map { it.eventId }) + updateFrozenResults(events) + onEventsUpdated(false) + } } override fun start() { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index 1eb6635df0..98b7473894 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -2393,7 +2393,6 @@ class TimelineFragment @Inject constructor( .setCancelable(true) .setNegativeButton(R.string.action_not_now) { _, _ -> } .setPositiveButton(R.string.action_try_it_out) { _, _ -> - timelineViewModel.onCleared() // We should first clear our viewModel threadsManager.enableThreadsAndRestart(it) } .show()