From cdd36ce034df8b1c061bd5f78902fb5ac6a5bcb6 Mon Sep 17 00:00:00 2001 From: ariskotsomitopoulos Date: Mon, 31 Jan 2022 11:56:26 +0200 Subject: [PATCH] Fix IndexOutOfBound crashes while clicking permalinks --- .../timeline/helper/TimelineControllerInterceptorHelper.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineControllerInterceptorHelper.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineControllerInterceptorHelper.kt index 7165921b35..8a0e1e18fd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineControllerInterceptorHelper.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/helper/TimelineControllerInterceptorHelper.kt @@ -115,7 +115,10 @@ class TimelineControllerInterceptorHelper(private val positionOfReadMarker: KMut private fun MutableList>.addForwardPrefetchIfNeeded(timeline: Timeline?, callback: TimelineEventController.Callback?) { val shouldAddForwardPrefetch = timeline?.hasMoreToLoad(Timeline.Direction.FORWARDS) ?: false if (shouldAddForwardPrefetch) { - val indexOfPrefetchForward = DEFAULT_PREFETCH_THRESHOLD.coerceAtMost(size - 1) + val indexOfPrefetchForward = DEFAULT_PREFETCH_THRESHOLD + .coerceAtMost(size - 1) + .coerceAtLeast(0) + val loadingItem = LoadingItem_() .id("prefetch_forward_loading${System.currentTimeMillis()}") .showLoader(false)