Skip to content

Commit

Permalink
!temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Dec 16, 2024
1 parent b2e5313 commit 9b91410
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
36 changes: 28 additions & 8 deletions crates/matrix-sdk-ui/src/timeline/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use ruma::{
},
serde::Raw,
EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedTransactionId, OwnedUserId,
TransactionId,
};
use tracing::{debug, error, field::debug, info, instrument, trace, warn};

Expand Down Expand Up @@ -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,
);
Expand All @@ -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,
);
Expand All @@ -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,
);
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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<Arc<TimelineItem>> {
Expand All @@ -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())
Expand Down
10 changes: 6 additions & 4 deletions crates/matrix-sdk-ui/src/timeline/tests/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 9b91410

Please sign in to comment.