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
This commit is contained in:
Jorge Martin Espinosa 2023-08-02 13:55:04 +02:00 committed by GitHub
parent 414bbd2f2c
commit f8ebb5930d
3 changed files with 6 additions and 4 deletions

View file

@ -91,7 +91,7 @@ class TimelinePresenter @Inject constructor(
} }
LaunchedEffect(timelineItems.size) { LaunchedEffect(timelineItems.size) {
computeHasNewItems(timelineItems, prevMostRecentItemId, hasNewItems) computeHasNewItems(timelineItems, prevMostRecentItemId, hasNewItems)
} }
LaunchedEffect(Unit) { LaunchedEffect(Unit) {

View file

@ -140,6 +140,7 @@ fun TimelineView(
} }
TimelineScrollHelper( TimelineScrollHelper(
isTimelineEmpty = state.timelineItems.isEmpty(),
lazyListState = lazyListState, lazyListState = lazyListState,
hasNewItems = state.hasNewItems, hasNewItems = state.hasNewItems,
onScrollFinishedAt = ::onScrollFinishedAt onScrollFinishedAt = ::onScrollFinishedAt
@ -242,6 +243,7 @@ fun TimelineItemRow(
@Composable @Composable
private fun BoxScope.TimelineScrollHelper( private fun BoxScope.TimelineScrollHelper(
isTimelineEmpty: Boolean,
lazyListState: LazyListState, lazyListState: LazyListState,
hasNewItems: Boolean, hasNewItems: Boolean,
onScrollFinishedAt: (Int) -> Unit, onScrollFinishedAt: (Int) -> Unit,
@ -259,8 +261,8 @@ private fun BoxScope.TimelineScrollHelper(
} }
} }
LaunchedEffect(isScrollFinished) { LaunchedEffect(isScrollFinished, isTimelineEmpty) {
if (isScrollFinished) { if (isScrollFinished && !isTimelineEmpty) {
// Notify the parent composable about the first visible item index when scrolling finishes // Notify the parent composable about the first visible item index when scrolling finishes
onScrollFinishedAt(lazyListState.firstVisibleItemIndex) onScrollFinishedAt(lazyListState.firstVisibleItemIndex)
} }

View file

@ -119,7 +119,7 @@ class TimelinePresenterTest {
} }
@Test @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( val timeline = FakeMatrixTimeline(
initialTimelineItems = listOf( initialTimelineItems = listOf(
MatrixTimelineItem.Event(0, anEventTimelineItem()) MatrixTimelineItem.Event(0, anEventTimelineItem())