diff --git a/bindings/matrix-sdk-ffi/changelog.d/6428.changed.md b/bindings/matrix-sdk-ffi/changelog.d/6428.changed.md new file mode 100644 index 00000000000..54c29241986 --- /dev/null +++ b/bindings/matrix-sdk-ffi/changelog.d/6428.changed.md @@ -0,0 +1 @@ +[**breaking**] Send redactions issued via `Timeline::redact_event` through the send queue. diff --git a/crates/matrix-sdk-ui/changelog.d/6428.changed.md b/crates/matrix-sdk-ui/changelog.d/6428.changed.md new file mode 100644 index 00000000000..3371edcebf4 --- /dev/null +++ b/crates/matrix-sdk-ui/changelog.d/6428.changed.md @@ -0,0 +1 @@ +[**breaking**] Send redactions issued via `Timeline::redact` through the send queue. diff --git a/crates/matrix-sdk-ui/src/timeline/error.rs b/crates/matrix-sdk-ui/src/timeline/error.rs index 28cbccb2148..06160df4ed6 100644 --- a/crates/matrix-sdk-ui/src/timeline/error.rs +++ b/crates/matrix-sdk-ui/src/timeline/error.rs @@ -44,6 +44,10 @@ pub enum Error { #[error("Failed sending attachment")] FailedSendingAttachment, + /// The redaction could not be sent. + #[error("Failed sending redaction")] + FailedSendingRedaction, + /// The reaction could not be toggled. #[error("Failed toggling reaction")] FailedToToggleReaction, diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index 53456f7f37d..cf25a5cc385 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -628,16 +628,20 @@ impl Timeline { match event.handle() { TimelineItemHandle::Remote(event_id) => { - self.room().redact(event_id, reason, None).await.map_err(RedactError::HttpError)?; + self.room() + .send_queue() + .redact(event_id.to_owned(), reason) + .await + .map_err(|_| Error::FailedSendingRedaction)?; + Ok(()) } TimelineItemHandle::Local(handle) => { if !handle.abort().await.map_err(RoomSendQueueError::StorageError)? { return Err(RedactError::InvalidLocalEchoState.into()); } + Ok(()) } } - - Ok(()) } /// Fetch unavailable details about the event with the given ID. diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/mod.rs b/crates/matrix-sdk-ui/tests/integration/timeline/mod.rs index cb99b4f30d4..bdf0568d55a 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/mod.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/mod.rs @@ -446,6 +446,20 @@ async fn test_redact_message() { timeline.redact(&first.as_event().unwrap().identifier(), Some("inapprops")).await.unwrap(); + assert_let_timeout!(Some(timeline_updates) = timeline_stream.next()); + assert_eq!(timeline_updates.len(), 1); + + assert_let!(VectorDiff::Set { index: 1, value: item } = &timeline_updates[0]); + assert!(item.as_event().unwrap().content().is_redacted()); + + assert_let_timeout!(Some(timeline_updates) = timeline_stream.next()); + assert_eq!(timeline_updates.len(), 2); + + assert_let!(VectorDiff::Set { index: 1, value: item } = &timeline_updates[0]); + assert!(item.as_event().unwrap().content().is_redacted()); + assert_let!(VectorDiff::Set { index: 1, value: item } = &timeline_updates[1]); + assert!(item.as_event().unwrap().content().is_redacted()); + // Redacting a local event works. timeline .send(RoomMessageEventContent::text_plain("i will disappear soon").into()) @@ -536,6 +550,26 @@ async fn test_redact_local_sent_message() { // Let's redact the local echo with the remote handle. timeline.redact(&event.identifier(), None).await.unwrap(); + + // We receive an update in the timeline from the send queue: the redaction's + // local echo. + assert_let_timeout!(Some(timeline_updates) = timeline_stream.next()); + assert_eq!(timeline_updates.len(), 1); + + assert_let!(VectorDiff::Set { index: 1, value: item } = &timeline_updates[0]); + let event = item.as_event().unwrap(); + assert!(event.content().is_redacted()); + + // We receive an update in the timeline from the send queue: the redaction's + // remote echo. + assert_let_timeout!(Some(timeline_updates) = timeline_stream.next()); + assert_eq!(timeline_updates.len(), 1); + + assert_let!(VectorDiff::Set { index: 1, value: item } = &timeline_updates[0]); + let event = item.as_event().unwrap(); + assert!(event.content().is_redacted()); + + assert_pending!(timeline_stream); } #[async_test]