events: Make redacted_because non-optional in RedactedUnsigned
This commit is contained in:
parent
67cc8e9e9c
commit
ad3c27d927
@ -38,6 +38,9 @@ Breaking changes:
|
|||||||
* Remove `events::reaction::Relation` and use `events::relation::Annotation` instead
|
* Remove `events::reaction::Relation` and use `events::relation::Annotation` instead
|
||||||
* Remove `events::key::verification::Relation` and use `events::relation::Reference` instead
|
* Remove `events::key::verification::Relation` and use `events::relation::Reference` instead
|
||||||
* Rename `events::relation::Relations` to `BundledRelations`
|
* Rename `events::relation::Relations` to `BundledRelations`
|
||||||
|
* Make the `redacted_because` field in `UnsignedRedacted` non-optional and replace parameterless
|
||||||
|
`new` constructor by one that takes a redaction event (like `new_because` previously, which is
|
||||||
|
now removed)
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
|
@ -143,33 +143,16 @@ impl<C: StateEventContent> Default for StateUnsigned<C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extra information about a redacted event that is not incorporated into the event's hash.
|
/// Extra information about a redacted event that is not incorporated into the event's hash.
|
||||||
#[derive(Clone, Debug, Default, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
pub struct RedactedUnsigned {
|
pub struct RedactedUnsigned {
|
||||||
/// The event that redacted this event, if any.
|
/// The event that redacted this event, if any.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
pub redacted_because: Box<SyncRoomRedactionEvent>,
|
||||||
pub redacted_because: Option<Box<SyncRoomRedactionEvent>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedactedUnsigned {
|
impl RedactedUnsigned {
|
||||||
/// Create a new `RedactedUnsigned` with field set to `None`.
|
/// Create a new `RedactedUnsigned` with the given redaction event.
|
||||||
pub fn new() -> Self {
|
pub fn new(redacted_because: Box<SyncRoomRedactionEvent>) -> Self {
|
||||||
Self::default()
|
Self { redacted_because }
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new `RedactedUnsigned` with the given redacted because.
|
|
||||||
pub fn new_because(redacted_because: Box<SyncRoomRedactionEvent>) -> Self {
|
|
||||||
Self { redacted_because: Some(redacted_because) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CanBeEmpty for RedactedUnsigned {
|
|
||||||
/// Whether this unsigned data is empty (`redacted_because` is `None`).
|
|
||||||
///
|
|
||||||
/// This method is used to determine whether to skip serializing the `unsigned` field in
|
|
||||||
/// redacted room events. Do not use it to determine whether an incoming `unsigned` field
|
|
||||||
/// was present - it could still have been present but contained none of the known fields.
|
|
||||||
fn is_empty(&self) -> bool {
|
|
||||||
self.redacted_because.is_none()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,6 @@ fn deserialize_redacted_state_event() {
|
|||||||
))) => redacted
|
))) => redacted
|
||||||
);
|
);
|
||||||
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
assert_eq!(redacted.event_id, "$h29iv0s8:example.com");
|
||||||
assert!(redacted.unsigned.redacted_because.is_some());
|
|
||||||
assert_eq!(redacted.content.creator, "@carl:example.com");
|
assert_eq!(redacted.content.creator, "@carl:example.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ fn expand_deserialize_event(
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if name == "unsigned" {
|
} else if name == "unsigned" && !var.is_redacted() {
|
||||||
if has_prev_content(kind, var) {
|
if has_prev_content(kind, var) {
|
||||||
quote! {
|
quote! {
|
||||||
let unsigned = unsigned.map(|json| {
|
let unsigned = unsigned.map(|json| {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user