client-api: Use Raw for create_room::Request::creation_content

This commit is contained in:
Jonas Platte 2021-10-24 00:36:22 +02:00
parent 401c0b07b3
commit e7f01ca55a
No known key found for this signature in database
GPG Key ID: 7D261D771D915378
3 changed files with 30 additions and 6 deletions

View File

@ -8,6 +8,7 @@ Breaking changes:
nested borrowing can be very annoying nested borrowing can be very annoying
* `LoginInfo` no longer implements `PartialEq` and `Eq` due to the custom variant that was added. * `LoginInfo` no longer implements `PartialEq` and `Eq` due to the custom variant that was added.
* `LoginInfo` converted to newtype variants. * `LoginInfo` converted to newtype variants.
* Use `Raw` for `create_room::Request::creation_content`
Improvements: Improvements:

View File

@ -31,8 +31,8 @@ ruma_api! {
#[derive(Default)] #[derive(Default)]
request: { request: {
/// Extra keys to be added to the content of the `m.room.create`. /// Extra keys to be added to the content of the `m.room.create`.
#[serde(default, skip_serializing_if = "CreationContent::is_empty")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub creation_content: CreationContent, pub creation_content: Option<Raw<CreationContent>>,
/// List of state events to send to the new room. /// List of state events to send to the new room.
/// ///

View File

@ -239,17 +239,19 @@ impl<'de> Deserialize<'de> for AllowRule {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[cfg(feature = "unstable-pre-spec")] use matches::assert_matches;
use super::AllowRule;
use super::{JoinRule, RoomJoinRulesEventContent};
#[cfg(feature = "unstable-pre-spec")] #[cfg(feature = "unstable-pre-spec")]
use ruma_identifiers::room_id; use ruma_identifiers::room_id;
#[cfg(feature = "unstable-pre-spec")]
use super::AllowRule;
use super::{JoinRule, RoomJoinRulesEvent, RoomJoinRulesEventContent};
#[test] #[test]
fn deserialize() { fn deserialize() {
let json = r#"{"join_rule": "public"}"#; let json = r#"{"join_rule": "public"}"#;
let event: RoomJoinRulesEventContent = serde_json::from_str(json).unwrap(); 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")] #[cfg(feature = "unstable-pre-spec")]
@ -280,4 +282,25 @@ mod tests {
rule => panic!("Deserialized to wrong variant: {:?}", rule), 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::<RoomJoinRulesEvent>(json), Ok(_));
}
} }