From dd24d6be778e55270f3400681d0b8c1ec8145597 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 13 Apr 2022 16:43:41 +0200 Subject: [PATCH] events: Add {RoomRedactionEvent, SyncRoomRedactionEvent}::as_original --- crates/ruma-common/src/events/room/redaction.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/ruma-common/src/events/room/redaction.rs b/crates/ruma-common/src/events/room/redaction.rs index 17772d2c..2cfe9f1e 100644 --- a/crates/ruma-common/src/events/room/redaction.rs +++ b/crates/ruma-common/src/events/room/redaction.rs @@ -230,6 +230,14 @@ impl RoomRedactionEvent { Self::Redacted(ev) => &ev.room_id, } } + + /// Get the inner `RoomRedactionEvent` if this is an unredacted event. + pub fn as_original(&self) -> Option<&OriginalRoomRedactionEvent> { + match self { + Self::Original(v) => Some(v), + _ => None, + } + } } impl Redact for RoomRedactionEvent { @@ -292,6 +300,14 @@ impl SyncRoomRedactionEvent { } } + /// Get the inner `SyncRoomRedactionEvent` if this is an unredacted event. + pub fn as_original(&self) -> Option<&OriginalSyncRoomRedactionEvent> { + match self { + Self::Original(v) => Some(v), + _ => None, + } + } + /// Convert this sync event into a full event (one with a `room_id` field). pub fn into_full_event(self, room_id: Box) -> RoomRedactionEvent { match self {