Skip to content

Commit

Permalink
timeline: update comments and error types for Timeline::redact
Browse files Browse the repository at this point in the history
Yay, one fewer error type for the timeline.
  • Loading branch information
bnjbvr committed Jul 22, 2024
1 parent ec057cf commit bbae536
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
16 changes: 6 additions & 10 deletions crates/matrix-sdk-ui/src/timeline/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
use matrix_sdk::{
event_cache::{paginator::PaginatorError, EventCacheError},
room::edit::EditError,
send_queue::{RoomSendQueueError, RoomSendQueueStorageError},
send_queue::RoomSendQueueError,
HttpError,
};
use thiserror::Error;

Expand Down Expand Up @@ -62,6 +63,10 @@ pub enum Error {
/// An error happened while attempting to edit an event.
#[error(transparent)]
EditError(#[from] EditError),

/// An error happened while attempting to redact an event.
#[error(transparent)]
RedactError(HttpError),
}

#[derive(Error, Debug)]
Expand Down Expand Up @@ -107,12 +112,3 @@ pub enum SendEventError {
#[error(transparent)]
RoomQueueError(#[from] RoomSendQueueError),
}

#[derive(Debug, Error)]
pub enum RedactEventError {
#[error(transparent)]
SdkError(#[from] matrix_sdk::Error),

#[error("an error happened while interacting with the room queue")]
RoomQueueError(#[source] RoomSendQueueStorageError),
}
22 changes: 10 additions & 12 deletions crates/matrix-sdk-ui/src/timeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,19 +667,20 @@ impl Timeline {
SendAttachment::new(self, path.into(), mime_type, config)
}

/// Redacts an event from the timeline.
/// Redact an event.
///
/// If it was a local event, this will *try* to cancel it, if it was not
/// being sent already. If the event was a remote event, then it will be
/// redacted by sending a redaction request to the server.
/// # Returns
///
/// Returns whether the redaction did happen. It can only return false for
/// local events that are being processed.
/// - Returns `Ok(true)` if the redact happened.
/// - Returns `Ok(false)` if the redact targets an item that has no local
/// nor matching remote item.
/// - Returns an error if there was an issue sending the redaction event, or
/// interacting with the sending queue.
pub async fn redact(
&self,
event: &EventTimelineItem,
reason: Option<&str>,
) -> Result<bool, RedactEventError> {
) -> Result<bool, Error> {
let event_id = match event.identifier() {
TimelineEventItemId::TransactionId(txn_id) => {
// See if we have an up-to-date timeline item with that transaction id.
Expand All @@ -690,7 +691,7 @@ impl Timeline {
return Ok(handle
.abort()
.await
.map_err(RedactEventError::RoomQueueError)?);
.map_err(RoomSendQueueError::StorageError)?);
}
}
} else {
Expand All @@ -702,10 +703,7 @@ impl Timeline {
TimelineEventItemId::EventId(event_id) => event_id,
};

self.room()
.redact(&event_id, reason, None)
.await
.map_err(|err| RedactEventError::SdkError(err.into()))?;
self.room().redact(&event_id, reason, None).await.map_err(Error::RedactError)?;

Ok(true)
}
Expand Down

0 comments on commit bbae536

Please sign in to comment.