Skip to main content

arminius_lib_events/
traits.rs

1// SPDX-FileCopyrightText: 2025 BWI GmbH
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! Public traits defining shared behavior.
6
7use ruma::UserId;
8
9use crate::errors::ValidationError;
10
11/// Trait for events that can be redacted in-place.
12///
13/// This trait provides redaction functionality for signed and verified events.
14///
15/// ## Usage
16///
17/// ```ignore
18/// use arminius_lib_events::Redactable;
19///
20/// // Redact a signed event
21/// signed_event.redact(&redactor_user_id, Some("spam".to_owned()))?;
22///
23/// // Redact a verified event
24/// verified_event.redact(&redactor_user_id, None)?;
25/// ```
26///
27/// ## Redacted Content
28///
29/// After redaction, the event content is modified to retain only the fields
30/// allowed by the Matrix specification for the event's room version. The event
31/// ID and signatures remain unchanged.
32pub trait Redactable {
33	/// Redact this event in-place.
34	///
35	/// This method modifies the event content according to Matrix redaction
36	/// rules while preserving the event ID and signatures.
37	///
38	/// ## Parameters
39	///
40	/// - `redactor`: User ID of the user performing the redaction.
41	/// - `reason`: Optional reason for the redaction.
42	///
43	/// ## Errors
44	///
45	/// Returns [`ValidationError`] if:
46	/// - Event content cannot be parsed as JSON
47	/// - Canonical JSON generation fails
48	/// - Redaction fails due to invalid event structure
49	fn redact(&mut self, redactor: &UserId, reason: Option<String>) -> Result<(), ValidationError>;
50}