Use Box instead of Raw for the redacted Unsigned types redacted_because
This commit is contained in:
parent
885aae39c5
commit
3a0138dea1
@ -379,7 +379,7 @@ fn generate_redacted_fields(
|
|||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
unsigned: ::ruma_events::#redaction_type {
|
unsigned: ::ruma_events::#redaction_type {
|
||||||
redacted_because: Some(::ruma_events::EventJson::from(redaction)),
|
redacted_because: Some(::std::boxed::Box::new(redaction)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -222,7 +222,7 @@ impl Unsigned {
|
|||||||
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")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub redacted_because: Option<Raw<RedactionEvent>>,
|
pub redacted_because: Option<Box<RedactionEvent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedactedUnsigned {
|
impl RedactedUnsigned {
|
||||||
@ -243,7 +243,7 @@ impl RedactedUnsigned {
|
|||||||
pub struct RedactedSyncUnsigned {
|
pub struct RedactedSyncUnsigned {
|
||||||
/// The event that redacted this event, if any.
|
/// The event that redacted this event, if any.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub redacted_because: Option<Raw<SyncRedactionEvent>>,
|
pub redacted_because: Option<Box<SyncRedactionEvent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RedactedSyncUnsigned {
|
impl RedactedSyncUnsigned {
|
||||||
|
@ -21,12 +21,12 @@ use ruma_events::{
|
|||||||
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
|
use ruma_identifiers::{EventId, RoomId, RoomVersionId, UserId};
|
||||||
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
|
||||||
|
|
||||||
fn full_unsigned() -> RedactedSyncUnsigned {
|
fn sync_unsigned() -> RedactedSyncUnsigned {
|
||||||
let mut unsigned = RedactedSyncUnsigned::default();
|
let mut unsigned = RedactedSyncUnsigned::default();
|
||||||
// The presence of `redacted_because` triggers the event enum to return early
|
// The presence of `redacted_because` triggers the event enum to return early
|
||||||
// with `RedactedContent` instead of failing to deserialize according
|
// with `RedactedContent` instead of failing to deserialize according
|
||||||
// to the event type string.
|
// to the event type string.
|
||||||
unsigned.redacted_because = Some(Raw::from(SyncRedactionEvent {
|
unsigned.redacted_because = Some(Box::new(SyncRedactionEvent {
|
||||||
content: RedactionEventContent { reason: Some("redacted because".into()) },
|
content: RedactionEventContent { reason: Some("redacted because".into()) },
|
||||||
redacts: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
redacts: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||||
@ -38,6 +38,21 @@ fn full_unsigned() -> RedactedSyncUnsigned {
|
|||||||
unsigned
|
unsigned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn full_unsigned() -> RedactedUnsigned {
|
||||||
|
let mut unsigned = RedactedUnsigned::default();
|
||||||
|
unsigned.redacted_because = Some(Box::new(RedactionEvent {
|
||||||
|
content: RedactionEventContent { reason: Some("redacted because".into()) },
|
||||||
|
room_id: RoomId::try_from("!roomid:room.com").unwrap(),
|
||||||
|
redacts: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||||
|
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||||
|
origin_server_ts: UNIX_EPOCH + Duration::from_millis(1),
|
||||||
|
sender: UserId::try_from("@carl:example.com").unwrap(),
|
||||||
|
unsigned: Unsigned::default(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
unsigned
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn redacted_message_event_serialize() {
|
fn redacted_message_event_serialize() {
|
||||||
let redacted = RedactedSyncMessageEvent {
|
let redacted = RedactedSyncMessageEvent {
|
||||||
@ -110,7 +125,7 @@ fn redacted_aliases_event_serialize_with_content() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn redacted_aliases_deserialize() {
|
fn redacted_aliases_deserialize() {
|
||||||
let unsigned = full_unsigned();
|
let unsigned = sync_unsigned();
|
||||||
|
|
||||||
let redacted = json!({
|
let redacted = json!({
|
||||||
"event_id": "$h29iv0s8:example.com",
|
"event_id": "$h29iv0s8:example.com",
|
||||||
@ -170,7 +185,7 @@ fn redacted_deserialize_any_room_sync() {
|
|||||||
// The presence of `redacted_because` triggers the event enum (AnySyncRoomEvent in this case)
|
// The presence of `redacted_because` triggers the event enum (AnySyncRoomEvent in this case)
|
||||||
// to return early with `RedactedContent` instead of failing to deserialize according
|
// to return early with `RedactedContent` instead of failing to deserialize according
|
||||||
// to the event type string.
|
// to the event type string.
|
||||||
unsigned.redacted_because = Some(Raw::from(RedactionEvent {
|
unsigned.redacted_because = Some(Box::new(RedactionEvent {
|
||||||
content: RedactionEventContent { reason: Some("redacted because".into()) },
|
content: RedactionEventContent { reason: Some("redacted because".into()) },
|
||||||
redacts: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
redacts: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||||
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
event_id: EventId::try_from("$h29iv0s8:example.com").unwrap(),
|
||||||
@ -204,7 +219,7 @@ fn redacted_deserialize_any_room_sync() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn redacted_state_event_deserialize() {
|
fn redacted_state_event_deserialize() {
|
||||||
let unsigned = full_unsigned();
|
let unsigned = sync_unsigned();
|
||||||
|
|
||||||
let redacted = json!({
|
let redacted = json!({
|
||||||
"content": {
|
"content": {
|
||||||
@ -237,7 +252,7 @@ fn redacted_state_event_deserialize() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn redacted_custom_event_serialize() {
|
fn redacted_custom_event_serialize() {
|
||||||
let unsigned = full_unsigned();
|
let unsigned = sync_unsigned();
|
||||||
|
|
||||||
let redacted = json!({
|
let redacted = json!({
|
||||||
"event_id": "$h29iv0s8:example.com",
|
"event_id": "$h29iv0s8:example.com",
|
||||||
@ -271,7 +286,7 @@ fn redacted_custom_event_serialize() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn redacted_custom_event_deserialize() {
|
fn redacted_custom_event_deserialize() {
|
||||||
let unsigned = full_unsigned();
|
let unsigned = sync_unsigned();
|
||||||
|
|
||||||
let redacted = RedactedSyncStateEvent {
|
let redacted = RedactedSyncStateEvent {
|
||||||
content: RedactedCustomEventContent { event_type: "m.made.up".into() },
|
content: RedactedCustomEventContent { event_type: "m.made.up".into() },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user