From e7f01ca55a1eff437bad754bf0554cc09f44ec2a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sun, 24 Oct 2021 00:36:22 +0200 Subject: [PATCH] client-api: Use Raw for create_room::Request::creation_content --- crates/ruma-client-api/CHANGELOG.md | 1 + .../src/r0/room/create_room.rs | 4 +-- crates/ruma-events/src/room/join_rules.rs | 31 ++++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/crates/ruma-client-api/CHANGELOG.md b/crates/ruma-client-api/CHANGELOG.md index 906bbd26..d3c65759 100644 --- a/crates/ruma-client-api/CHANGELOG.md +++ b/crates/ruma-client-api/CHANGELOG.md @@ -8,6 +8,7 @@ Breaking changes: nested borrowing can be very annoying * `LoginInfo` no longer implements `PartialEq` and `Eq` due to the custom variant that was added. * `LoginInfo` converted to newtype variants. +* Use `Raw` for `create_room::Request::creation_content` Improvements: diff --git a/crates/ruma-client-api/src/r0/room/create_room.rs b/crates/ruma-client-api/src/r0/room/create_room.rs index 2d9d6087..0166bb9f 100644 --- a/crates/ruma-client-api/src/r0/room/create_room.rs +++ b/crates/ruma-client-api/src/r0/room/create_room.rs @@ -31,8 +31,8 @@ ruma_api! { #[derive(Default)] request: { /// Extra keys to be added to the content of the `m.room.create`. - #[serde(default, skip_serializing_if = "CreationContent::is_empty")] - pub creation_content: CreationContent, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub creation_content: Option>, /// List of state events to send to the new room. /// diff --git a/crates/ruma-events/src/room/join_rules.rs b/crates/ruma-events/src/room/join_rules.rs index 97d942f9..c6a63003 100644 --- a/crates/ruma-events/src/room/join_rules.rs +++ b/crates/ruma-events/src/room/join_rules.rs @@ -239,17 +239,19 @@ impl<'de> Deserialize<'de> for AllowRule { #[cfg(test)] mod tests { - #[cfg(feature = "unstable-pre-spec")] - use super::AllowRule; - use super::{JoinRule, RoomJoinRulesEventContent}; + use matches::assert_matches; #[cfg(feature = "unstable-pre-spec")] use ruma_identifiers::room_id; + #[cfg(feature = "unstable-pre-spec")] + use super::AllowRule; + use super::{JoinRule, RoomJoinRulesEvent, RoomJoinRulesEventContent}; + #[test] fn deserialize() { let json = r#"{"join_rule": "public"}"#; let event: RoomJoinRulesEventContent = serde_json::from_str(json).unwrap(); - assert!(matches!(event, RoomJoinRulesEventContent { join_rule: JoinRule::Public })); + assert_matches!(event, RoomJoinRulesEventContent { join_rule: JoinRule::Public }); } #[cfg(feature = "unstable-pre-spec")] @@ -280,4 +282,25 @@ mod tests { rule => panic!("Deserialized to wrong variant: {:?}", rule), } } + + fn deserialize_restricted_event() { + let json = r#"{ + "type": "m.room.join_rules", + "sender": "@admin:community.rs", + "content": { + "join_rule": "restricted", + "allow":[ + { "type": "m.room_membership","room_id": "!KqeUnzmXPIhHRaWMTs:mccarty.io" } + ] + }, + "state_key": "", + "origin_server_ts":1630508835342, + "unsigned": { + "age":4165521871 + }, + "event_id": "$0ACb9KSPlT3al3kikyRYvFhMqXPP9ZcQOBrsdIuh58U" + }"#; + + assert_matches!(serde_json::from_str::(json), Ok(_)); + } }