From 57c0d86ce38fba377a05c6c02b5a969e66e7a0b3 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 2 Jul 2024 16:27:38 +0200 Subject: [PATCH] timeline: when aborting fails on a local echo, retry on the matching remote echo --- crates/matrix-sdk-ui/src/timeline/mod.rs | 39 ++++++++++++++++-------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index ac9f9801413..0eac7bc2d18 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -100,7 +100,6 @@ pub use self::{ virtual_item::VirtualTimelineItem, }; use self::{ - event_item::EventTimelineItemKind, futures::SendAttachment, inner::{ReactionAction, TimelineInner}, reactions::ReactionToggleResult, @@ -791,25 +790,39 @@ impl Timeline { event: &EventTimelineItem, reason: Option<&str>, ) -> Result { - match &event.kind { - EventTimelineItemKind::Local(local) => { + let event_id = match event.identifier() { + TimelineEventItemId::TransactionId(txn_id) => { + let local = event.as_local().unwrap(); + if let Some(handle) = local.send_handle.clone() { - Ok(handle.abort().await.map_err(RedactEventError::RoomQueueError)?) + if handle.abort().await.map_err(RedactEventError::RoomQueueError)? { + return Ok(true); + } + + if let Some(event_id) = self.find_remote_by_transaction_id(&txn_id).await { + event_id + } else { + warn!("Couldn't find the local echo anymore, nor a matching remote echo"); + return Ok(false); + } } else { // No abort handle; theoretically unreachable for regular usage of the // timeline, but this may happen in testing contexts. - Err(RedactEventError::UnsupportedRedactLocal(local.transaction_id.clone())) + return Err(RedactEventError::UnsupportedRedactLocal( + local.transaction_id.clone(), + )); } } - EventTimelineItemKind::Remote(remote) => { - self.room() - .redact(&remote.event_id, reason, None) - .await - .map_err(|err| RedactEventError::SdkError(err.into()))?; - Ok(true) - } - } + TimelineEventItemId::EventId(event_id) => event_id, + }; + + self.room() + .redact(&event_id, reason, None) + .await + .map_err(|err| RedactEventError::SdkError(err.into()))?; + + Ok(true) } /// Fetch unavailable details about the event with the given ID.