diff --git a/crates/matrix-sdk-ui/src/timeline/event_handler.rs b/crates/matrix-sdk-ui/src/timeline/event_handler.rs index e4338d0793..bcfbaffba9 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_handler.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_handler.rs @@ -46,6 +46,7 @@ use ruma::{ }, serde::Raw, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId, OwnedUserId, + TransactionId, }; use tracing::{debug, error, field::debug, info, instrument, trace, warn}; @@ -1096,12 +1097,14 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { ); match &self.ctx.flow { - Flow::Local { .. } => { + Flow::Local { txn_id, .. } => { trace!("Adding new local timeline item"); let removed_duplicated_timeline_item = Self::deduplicate_local_timeline_item( &mut self.items, &mut item, + None, + Some(&txn_id), &self.meta, &self.settings, ); @@ -1111,10 +1114,14 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { self.items.push_back(item, None); } - Flow::Remote { position: TimelineItemPosition::Start { .. }, .. } => { + Flow::Remote { + position: TimelineItemPosition::Start { .. }, event_id, txn_id, .. + } => { let removed_duplicated_timeline_item = Self::deduplicate_local_timeline_item( &mut self.items, &mut item, + Some(&event_id), + txn_id.as_ref().map(AsRef::as_ref), &self.meta, &self.settings, ); @@ -1126,10 +1133,17 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { self.items.push_front(item, Some(0)); } - Flow::Remote { position: TimelineItemPosition::At { event_index, .. }, .. } => { + Flow::Remote { + position: TimelineItemPosition::At { event_index, .. }, + event_id, + txn_id, + .. + } => { let removed_duplicated_timeline_item = Self::deduplicate_local_timeline_item( &mut self.items, &mut item, + Some(&event_id), + txn_id.as_ref().map(AsRef::as_ref), &self.meta, &self.settings, ); @@ -1183,11 +1197,15 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { self.items.insert(timeline_item_index, item, Some(event_index)); } - Flow::Remote { position: TimelineItemPosition::End { .. }, event_id, .. } => { + Flow::Remote { + position: TimelineItemPosition::End { .. }, event_id, txn_id, .. + } => { dbg!(&item); let removed_duplicated_timeline_item = Self::deduplicate_local_timeline_item( &mut self.items, &mut item, + Some(&event_id), + txn_id.as_ref().map(AsRef::as_ref), &self.meta, &self.settings, ); @@ -1283,6 +1301,8 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { fn deduplicate_local_timeline_item( items: &mut ObservableItemsTransaction<'_>, new_event_timeline_item: &mut EventTimelineItem, + event_id: Option<&EventId>, + transaction_id: Option<&TransactionId>, metadata: &TimelineMetadata, settings: &TimelineSettings, ) -> Option> { @@ -1305,14 +1325,14 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { } } - let event_id = new_event_timeline_item.event_id(); - let transaction_id = new_event_timeline_item.transaction_id(); - // Start with the canonical case: detect a local timeline item that matches // `event_id` or `transaction_id`. if let Some((local_timeline_item_index, local_timeline_item)) = rfind_event_item(items, |event_timeline_item| { - if event_timeline_item.is_local_echo() { + dbg!("=============================================="); + if dbg!(event_timeline_item.is_local_echo()) { + dbg!(&event_id, event_timeline_item.event_id()); + dbg!(&transaction_id, event_timeline_item.transaction_id()); event_id == event_timeline_item.event_id() || (transaction_id.is_some() && transaction_id == event_timeline_item.transaction_id()) diff --git a/crates/matrix-sdk-ui/src/timeline/tests/echo.rs b/crates/matrix-sdk-ui/src/timeline/tests/echo.rs index 106906b06b..683f643ec8 100644 --- a/crates/matrix-sdk-ui/src/timeline/tests/echo.rs +++ b/crates/matrix-sdk-ui/src/timeline/tests/echo.rs @@ -177,12 +177,14 @@ async fn test_remote_echo_new_position() { .await; // … the remote echo replaces the previous event. - let item = assert_next_matches!(stream, VectorDiff::Set { index: 3, value } => value); + assert_next_matches!(stream, VectorDiff::Remove { index: 3 }); + let item = assert_next_matches!(stream, VectorDiff::Insert { index: 2, value} => value); assert!(!item.as_event().unwrap().is_local_echo()); - // … the date divider is removed (because both bob's and alice's message are - // from the same day according to server timestamps). - assert_next_matches!(stream, VectorDiff::Remove { index: 2 }); + // Date divider is updated. + assert_next_matches!(stream, VectorDiff::Remove { index: 3 }); + + assert_pending!(stream); } #[async_test]