From a0cc9167422e40611b8795a60577891fc92a418a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Wed, 21 Dec 2022 17:17:02 +0100 Subject: [PATCH] events: Fix space state events optional booleans ser/de --- crates/ruma-common/src/events/space/child.rs | 27 ++++--------------- crates/ruma-common/src/events/space/parent.rs | 7 +++-- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/crates/ruma-common/src/events/space/child.rs b/crates/ruma-common/src/events/space/child.rs index c34c56b5..9c5edff1 100644 --- a/crates/ruma-common/src/events/space/child.rs +++ b/crates/ruma-common/src/events/space/child.rs @@ -40,8 +40,8 @@ pub struct SpaceChildEventContent { /// example by showing them eagerly in the room list. A child which is missing the `suggested` /// property is treated identically to a child with `"suggested": false`. A suggested child may /// be a room or a subspace. - #[serde(skip_serializing_if = "Option::is_none")] - pub suggested: Option, + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub suggested: bool, } impl SpaceChildEventContent { @@ -82,13 +82,12 @@ mod tests { let content = SpaceChildEventContent { via: Some(vec![server_name!("example.com").to_owned()]), order: Some("uwu".to_owned()), - suggested: Some(false), + suggested: false, }; let json = json!({ "via": ["example.com"], "order": "uwu", - "suggested": false, }); assert_eq!(to_json_value(&content).unwrap(), json); @@ -96,29 +95,13 @@ mod tests { #[test] fn space_child_empty_serialization() { - let content = SpaceChildEventContent { via: None, order: None, suggested: None }; + let content = SpaceChildEventContent { via: None, order: None, suggested: false }; let json = json!({}); assert_eq!(to_json_value(&content).unwrap(), json); } - #[test] - fn hierarchy_space_child_serialization() { - let content = SpaceChildEventContent { - via: Some(vec![server_name!("example.com").to_owned()]), - order: Some("uwu".to_owned()), - suggested: None, - }; - - let json = json!({ - "via": ["example.com"], - "order": "uwu", - }); - - assert_eq!(to_json_value(&content).unwrap(), json); - } - #[test] fn hierarchy_space_child_deserialization() { let json = json!({ @@ -141,6 +124,6 @@ mod tests { assert_eq!(via.len(), 1); assert_eq!(via[0], "example.org"); assert_eq!(ev.content.order, None); - assert_eq!(ev.content.suggested, None); + assert!(!ev.content.suggested); } } diff --git a/crates/ruma-common/src/events/space/parent.rs b/crates/ruma-common/src/events/space/parent.rs index 47c714b3..1e609bb6 100644 --- a/crates/ruma-common/src/events/space/parent.rs +++ b/crates/ruma-common/src/events/space/parent.rs @@ -29,6 +29,7 @@ pub struct SpaceParentEventContent { /// together. In practice, well behaved rooms should only have one `canonical` parent, but /// given this is not enforced: if multiple are present the client should select the one with /// the lowest room ID, as determined via a lexicographic ordering of the Unicode code-points. + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] pub canonical: bool, } @@ -63,11 +64,9 @@ mod tests { #[test] fn space_parent_empty_serialization() { - let content = SpaceParentEventContent { via: None, canonical: true }; + let content = SpaceParentEventContent { via: None, canonical: false }; - let json = json!({ - "canonical": true, - }); + let json = json!({}); assert_eq!(to_json_value(&content).unwrap(), json); }