From b78bbc01a0f1c1308bb53a32fbb3bfaefec497e1 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 4 Apr 2024 09:48:45 +0200 Subject: [PATCH] timeline: pin all the local echoes to the bottom Before this patch, only local echoes that were messages not sent or messages succesfully sent (but not ack'd yet by sync) would be pinned to the bottom. This fixes it by also pinning events that failed to send. Fixes #3287. --- crates/matrix-sdk-ui/src/timeline/event_handler.rs | 10 +--------- .../matrix-sdk-ui/tests/integration/timeline/queue.rs | 6 +++--- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/event_handler.rs b/crates/matrix-sdk-ui/src/timeline/event_handler.rs index 1a5bfbb60..f318e941c 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_handler.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_handler.rs @@ -951,15 +951,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { .iter() .enumerate() .rev() - .filter_map(|(idx, item)| Some((idx, item.as_event()?))) - .find(|(_, item)| { - !matches!( - item.send_state(), - Some(EventSendState::NotSentYet | EventSendState::Sent { .. }) - ) - }) - .unzip() - .0; + .find_map(|(idx, item)| (!item.as_event()?.is_local_echo()).then_some(idx)); // Insert the next item after the latest event item that's not a // pending local echo, or at the start if there is no such item. diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/queue.rs b/crates/matrix-sdk-ui/tests/integration/timeline/queue.rs index a9e30239b..66048d581 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/queue.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/queue.rs @@ -273,10 +273,10 @@ async fn test_clear_with_echoes() { let event_items: Vec<_> = timeline_items.iter().filter_map(|item| item.as_event()).collect(); assert_eq!(event_items.len(), 3); - // The message that failed to send. - assert_matches!(event_items[0].send_state(), Some(EventSendState::SendingFailed { .. })); // The message that came in from sync. - assert_matches!(event_items[1].origin(), Some(EventItemOrigin::Sync)); + assert_matches!(event_items[0].origin(), Some(EventItemOrigin::Sync)); + // The message that failed to send. + assert_matches!(event_items[1].send_state(), Some(EventSendState::SendingFailed { .. })); // The message that is still pending. assert_matches!(event_items[2].send_state(), Some(EventSendState::NotSentYet));