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));