refactor(timeline): include the bundled item owner in edit aggregation metadata

This commit is contained in:
Benjamin Bouvier
2025-06-09 17:07:52 +02:00
parent ca0fc3cf6d
commit 9fca8f0007
3 changed files with 14 additions and 2 deletions

View File

@@ -83,6 +83,10 @@ pub(in crate::timeline) struct PendingEdit {
/// The encryption info for this edit.
pub encryption_info: Option<Arc<EncryptionInfo>>,
/// If provided, this is the identifier of a remote event item that included
/// this bundled edit.
pub bundled_item_owner: Option<OwnedEventId>,
}
/// 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::<OwnedUserId>("sender").ok().flatten() else {

View File

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

View File

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