diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt index 082f18e449..c53d8fc279 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt @@ -91,7 +91,7 @@ class TimelinePresenter @Inject constructor( } LaunchedEffect(timelineItems.size) { - computeHasNewItems(timelineItems, prevMostRecentItemId, hasNewItems) + computeHasNewItems(timelineItems, prevMostRecentItemId, hasNewItems) } LaunchedEffect(Unit) { diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt index 9f81e612ba..6e16a3b92d 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt @@ -140,6 +140,7 @@ fun TimelineView( } TimelineScrollHelper( + isTimelineEmpty = state.timelineItems.isEmpty(), lazyListState = lazyListState, hasNewItems = state.hasNewItems, onScrollFinishedAt = ::onScrollFinishedAt @@ -242,6 +243,7 @@ fun TimelineItemRow( @Composable private fun BoxScope.TimelineScrollHelper( + isTimelineEmpty: Boolean, lazyListState: LazyListState, hasNewItems: Boolean, onScrollFinishedAt: (Int) -> Unit, @@ -259,8 +261,8 @@ private fun BoxScope.TimelineScrollHelper( } } - LaunchedEffect(isScrollFinished) { - if (isScrollFinished) { + LaunchedEffect(isScrollFinished, isTimelineEmpty) { + if (isScrollFinished && !isTimelineEmpty) { // Notify the parent composable about the first visible item index when scrolling finishes onScrollFinishedAt(lazyListState.firstVisibleItemIndex) } diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/timeline/TimelinePresenterTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/timeline/TimelinePresenterTest.kt index 345884f7bf..b4bb14f672 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/timeline/TimelinePresenterTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/timeline/TimelinePresenterTest.kt @@ -119,7 +119,7 @@ class TimelinePresenterTest { } @Test - fun `present - on scroll finished will not send read receipt no event is before the index`() = runTest { + fun `present - on scroll finished will not send read receipt if no event is before the index`() = runTest { val timeline = FakeMatrixTimeline( initialTimelineItems = listOf( MatrixTimelineItem.Event(0, anEventTimelineItem())