diff --git a/crates/matrix-sdk-ui/src/timeline/controller/aggregations.rs b/crates/matrix-sdk-ui/src/timeline/controller/aggregations.rs index ba8d4882d..1b5185b76 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/aggregations.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/aggregations.rs @@ -83,6 +83,10 @@ pub(in crate::timeline) struct PendingEdit { /// The encryption info for this edit. pub encryption_info: Option>, + + /// If provided, this is the identifier of a remote event item that included + /// this bundled edit. + pub bundled_item_owner: Option, } /// Which kind of aggregation (related event) is this? @@ -598,7 +602,12 @@ fn resolve_edits( TimelineEventItemId::EventId(event_id) => { if let Some(best_edit_pos) = &mut best_edit_pos { - let pos = items.position_by_event_id(event_id); + // Find the position of the timeline owning the edit: either the bundled + // item owner if this was a bundled edit, or the edit event itself. + let pos = items.position_by_event_id( + pending_edit.bundled_item_owner.as_ref().unwrap_or(event_id), + ); + if let Some(pos) = pos { // If the edit is more recent (higher index) than the previous best // edit we knew about, use this one. @@ -642,7 +651,7 @@ fn resolve_edits( /// Returns true if the edit was applied, false otherwise (because the edit and /// original timeline item types didn't match, for instance). fn edit_item(item: &mut Cow<'_, EventTimelineItem>, edit: PendingEdit) -> bool { - let PendingEdit { kind: edit_kind, edit_json, encryption_info } = edit; + let PendingEdit { kind: edit_kind, edit_json, encryption_info, bundled_item_owner: _ } = edit; if let Some(event_json) = &edit_json { let Some(edit_sender) = event_json.get_field::("sender").ok().flatten() else { diff --git a/crates/matrix-sdk-ui/src/timeline/controller/metadata.rs b/crates/matrix-sdk-ui/src/timeline/controller/metadata.rs index c50a1bc32..085d6f846 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/metadata.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/metadata.rs @@ -390,6 +390,7 @@ impl TimelineMetadata { )), edit_json, encryption_info: ctx.bundled_edit_encryption_info, + bundled_item_owner: Some(ctx.event_id.to_owned()), }), ); self.aggregations.add( @@ -427,6 +428,7 @@ impl TimelineMetadata { )), edit_json, encryption_info: ctx.bundled_edit_encryption_info, + bundled_item_owner: Some(ctx.event_id.to_owned()), }), ); self.aggregations.add( diff --git a/crates/matrix-sdk-ui/src/timeline/event_handler.rs b/crates/matrix-sdk-ui/src/timeline/event_handler.rs index c1bc1736c..f8d87e11a 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_handler.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_handler.rs @@ -574,6 +574,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { kind: edit_kind, edit_json: self.ctx.flow.raw_event().cloned(), encryption_info, + bundled_item_owner: None, }), );