From 4fd0f2a32c02e12ca36f74cb3fa7cecc773fce85 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 19 May 2025 12:48:56 +0200 Subject: [PATCH] refactor(timeline): slightly optimize flow for saving a bundled edit We only need the edit_json if we're about to save the edit aggregation. Likewise, if there's no current event id (i.e. the event being handled is a local echo), then we don't need to even try to extract anything from the bundle information. --- crates/matrix-sdk-ui/src/timeline/event_handler.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/event_handler.rs b/crates/matrix-sdk-ui/src/timeline/event_handler.rs index adb870501..a0681eda0 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_handler.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_handler.rs @@ -372,14 +372,13 @@ impl TimelineAction { c, )) => { // Record the bundled edit in the aggregations set, if any. - if let Some(new_content) = relations.and_then(extract_poll_edit_content) { - let edit_json = raw_event.and_then(extract_bundled_edit_event_json); - - if let Some(target_id) = event_id { + if let Some(target_id) = event_id { + if let Some(new_content) = relations.and_then(extract_poll_edit_content) { // It is replacing the current event. if let Some(edit_event_id) = raw_event.and_then(|raw_event| { raw_event.get_field::("event_id").ok().flatten() }) { + let edit_json = raw_event.and_then(extract_bundled_edit_event_json); let aggregation = Aggregation::new( TimelineEventItemId::EventId(edit_event_id), AggregationKind::Edit(PendingEdit { @@ -420,14 +419,13 @@ impl TimelineAction { AnyMessageLikeEventContent::RoomMessage(msg) => { // Record the bundled edit in the aggregations set, if any. - if let Some(new_content) = relations.and_then(extract_room_msg_edit_content) { - let edit_json = raw_event.and_then(extract_bundled_edit_event_json); - - if let Some(target_id) = event_id { + if let Some(target_id) = event_id { + if let Some(new_content) = relations.and_then(extract_room_msg_edit_content) { // It is replacing the current event. if let Some(edit_event_id) = raw_event.and_then(|raw_event| { raw_event.get_field::("event_id").ok().flatten() }) { + let edit_json = raw_event.and_then(extract_bundled_edit_event_json); let aggregation = Aggregation::new( TimelineEventItemId::EventId(edit_event_id), AggregationKind::Edit(PendingEdit {