From 58ed74607daa9742c5ed88eea82cba1ce5150498 Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Wed, 2 Aug 2023 13:55:04 +0200 Subject: [PATCH] Fix sending read receipts when entering a room (#1016) * Fix sending read receipts when entering a room * Improve solution for sending a read receipt when opening a room * Roll back previous solution as it broke unit tests * Remove dead code --- .../features/messages/impl/timeline/TimelinePresenter.kt | 2 +- .../android/features/messages/impl/timeline/TimelineView.kt | 6 ++++-- .../features/messages/timeline/TimelinePresenterTest.kt | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) 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())