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.
This commit is contained in:
Benjamin Bouvier
2025-05-19 12:48:56 +02:00
parent 74d5d6e265
commit 4fd0f2a32c

View File

@@ -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::<OwnedEventId>("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::<OwnedEventId>("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 {