canonical-json: Allow to converted (Sync)RoomRedactionEvent to RedactedBecause

With room version 11, even a redacted event has a redacts field.
This commit is contained in:
Kévin Commaille 2023-08-22 12:13:23 +02:00 committed by Kévin Commaille
parent 8e10064364
commit 533da2aded

View File

@ -11,7 +11,10 @@ pub use self::value::{CanonicalJsonObject, CanonicalJsonValue};
use crate::RoomVersionId;
#[cfg(feature = "events")]
use crate::{
events::room::redaction::{OriginalRoomRedactionEvent, OriginalSyncRoomRedactionEvent},
events::room::redaction::{
OriginalRoomRedactionEvent, OriginalSyncRoomRedactionEvent, RoomRedactionEvent,
SyncRoomRedactionEvent,
},
serde::Raw,
};
@ -150,6 +153,24 @@ impl TryFrom<&Raw<OriginalSyncRoomRedactionEvent>> for RedactedBecause {
}
}
#[cfg(feature = "events")]
impl TryFrom<&Raw<RoomRedactionEvent>> for RedactedBecause {
type Error = serde_json::Error;
fn try_from(value: &Raw<RoomRedactionEvent>) -> Result<Self, Self::Error> {
value.deserialize_as().map(Self)
}
}
#[cfg(feature = "events")]
impl TryFrom<&Raw<SyncRoomRedactionEvent>> for RedactedBecause {
type Error = serde_json::Error;
fn try_from(value: &Raw<SyncRoomRedactionEvent>) -> Result<Self, Self::Error> {
value.deserialize_as().map(Self)
}
}
/// Redacts an event using the rules specified in the Matrix client-server specification.
///
/// This is part of the process of signing an event.