From ac9b551d25c22778dfcd208f3dd4a31de2016ed5 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 16 Oct 2024 14:37:25 +0200 Subject: [PATCH] chore(ffi): revert to using a room method to edit if a remote event couldn't be found in the timeline This maintains functionality we had prior to the previous commit: if an event's missing from the timeline (e.g. timeline's been cleared after a gappy sync response), then still allow editing it. --- bindings/matrix-sdk-ffi/src/timeline/mod.rs | 27 +++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/timeline/mod.rs b/bindings/matrix-sdk-ffi/src/timeline/mod.rs index 5c10b3c2565..c8b6dc3d897 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/mod.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/mod.rs @@ -494,11 +494,28 @@ impl Timeline { &self, event_or_transaction_id: EventOrTransactionId, new_content: EditedContent, - ) -> Result { - self.inner - .edit(&(event_or_transaction_id.try_into()?), new_content.try_into()?) - .await - .map_err(Into::into) + ) -> Result<(), ClientError> { + let edited = self + .inner + .edit(&(event_or_transaction_id.clone().try_into()?), new_content.clone().try_into()?) + .await?; + + if !edited { + // If we couldn't edit, assume it was an (remote) event that wasn't in the + // timeline, and try to edit it via the room itself. + let event_id = match event_or_transaction_id { + EventOrTransactionId::EventId { event_id } => EventId::parse(event_id)?, + EventOrTransactionId::TransactionId { .. } => { + warn!("trying to apply an edit to a local echo that doesn't exist in this timeline, aborting"); + return Ok(()); + } + }; + let room = self.inner.room(); + let edit_event = room.make_edit_event(&event_id, new_content.try_into()?).await?; + room.send_queue().send(edit_event).await?; + } + + Ok(()) } pub async fn send_location(