From c37843e9be619ffac8c4d33ad3a6a175cc32610c Mon Sep 17 00:00:00 2001 From: Matthias Ahouansou Date: Thu, 27 Jun 2024 17:04:54 +0100 Subject: [PATCH] events: make allow field for restricted rooms optional In the spec, it doesn't state that it is a required field, even for restricted rooms --- crates/ruma-events/CHANGELOG.md | 1 + crates/ruma-events/src/room/join_rules.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/crates/ruma-events/CHANGELOG.md b/crates/ruma-events/CHANGELOG.md index e062ecf2..7d5f8412 100644 --- a/crates/ruma-events/CHANGELOG.md +++ b/crates/ruma-events/CHANGELOG.md @@ -6,6 +6,7 @@ Bug fixes: fragment. - Fix serialization of `room::message::Relation` and `room::encrypted::Relation` which could cause duplicate `rel_type` keys. +- `Restricted` no longer fails to deserialize when the `allow` field is missing Improvements: diff --git a/crates/ruma-events/src/room/join_rules.rs b/crates/ruma-events/src/room/join_rules.rs index 0ac9ef24..2cc50f0a 100644 --- a/crates/ruma-events/src/room/join_rules.rs +++ b/crates/ruma-events/src/room/join_rules.rs @@ -168,6 +168,7 @@ impl From for SpaceRoomJoinRule { #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub struct Restricted { /// Allow rules which describe conditions that allow joining a room. + #[serde(default)] pub allow: Vec, } @@ -324,6 +325,16 @@ mod tests { assert_eq!(serde_json::to_string(&allow_rule).unwrap(), json); } + #[test] + fn restricted_room_no_allow_field() { + let json = r#"{"join_rule":"restricted"}"#; + let join_rules: RoomJoinRulesEventContent = serde_json::from_str(json).unwrap(); + assert_matches!( + join_rules, + RoomJoinRulesEventContent { join_rule: JoinRule::Restricted(_) } + ); + } + #[test] fn join_rule_to_space_room_join_rule() { assert_eq!(SpaceRoomJoinRule::Invite, JoinRule::Invite.into());