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.
This commit is contained in:
Benjamin Bouvier
2024-04-04 09:48:45 +02:00
parent 682c17c9d8
commit b78bbc01a0
2 changed files with 4 additions and 12 deletions

View File

@@ -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.

View File

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