From 38e2d0bdcd7ab5c56ace392b36dc60f2e03d64b8 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 15 Feb 2023 16:15:16 +0100 Subject: [PATCH] fix(sdk): Fix day divider removal logic in timeline --- crates/matrix-sdk/src/room/timeline/event_handler.rs | 4 ++-- crates/matrix-sdk/src/room/timeline/tests/echo.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/matrix-sdk/src/room/timeline/event_handler.rs b/crates/matrix-sdk/src/room/timeline/event_handler.rs index dde2c222f..022fbb1ae 100644 --- a/crates/matrix-sdk/src/room/timeline/event_handler.rs +++ b/crates/matrix-sdk/src/room/timeline/event_handler.rs @@ -700,12 +700,12 @@ impl<'a, 'i> TimelineEventHandler<'a, 'i> { // Pre-requisites for removing the day divider: // 1. there is one preceding the old item at all if self.timeline_items[idx - 1].is_day_divider() - // 2. the next item after the old one being removed + // 2. the item after the old one that was removed // is virtual (it should be impossible for this // to be a read marker) && self .timeline_items - .get(idx + 1) + .get(idx) .map_or(true, |item| item.is_virtual()) { trace!("Removing day divider"); diff --git a/crates/matrix-sdk/src/room/timeline/tests/echo.rs b/crates/matrix-sdk/src/room/timeline/tests/echo.rs index 677f26acd..06e24281a 100644 --- a/crates/matrix-sdk/src/room/timeline/tests/echo.rs +++ b/crates/matrix-sdk/src/room/timeline/tests/echo.rs @@ -136,8 +136,11 @@ async fn remote_echo_new_position() { // … the local echo should be removed assert_matches!(stream.next().await, Some(VecDiff::RemoveAt { index: 1 })); + // … along with its day divider + assert_matches!(stream.next().await, Some(VecDiff::RemoveAt { index: 0 })); - // … and the remote echo added + // … and the remote echo added (no new day divider because both bob's and + // alice's message are from the same day according to server timestamps) let item = assert_matches!(stream.next().await, Some(VecDiff::Push { value }) => value); assert_matches!(item.as_event().unwrap(), EventTimelineItem::Remote(_)); }