From 7ab6e3ed0266964db5d84569b3585bf8c2932e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 17 Oct 2022 19:08:32 +0200 Subject: [PATCH] federation-api: Add the event field to RoomState According to MSC3083 --- crates/ruma-federation-api/CHANGELOG.md | 4 ++++ .../src/membership/create_join_event.rs | 11 +++++++++-- crates/ruma-federation-api/src/serde/v1_pdu.rs | 14 ++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/crates/ruma-federation-api/CHANGELOG.md b/crates/ruma-federation-api/CHANGELOG.md index 3fd78a2d..3f176204 100644 --- a/crates/ruma-federation-api/CHANGELOG.md +++ b/crates/ruma-federation-api/CHANGELOG.md @@ -1,5 +1,9 @@ # [unreleased] +Bug fixes: + +* Add the `event` field to `RoomState` according to MSC3083 / Matrix v1.2 + # 0.6.0 Breaking changes: diff --git a/crates/ruma-federation-api/src/membership/create_join_event.rs b/crates/ruma-federation-api/src/membership/create_join_event.rs index 814aae75..17862521 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event.rs @@ -22,6 +22,13 @@ pub struct RoomState { /// The room state. pub state: Vec>, + + /// The signed copy of the membership event sent to other servers by the + /// resident server, including the resident server's signature. + /// + /// Required if the room version supports restricted join rules. + #[serde(skip_serializing_if = "Option::is_none")] + pub event: Option>, } #[cfg(feature = "unstable-unspecified")] @@ -38,7 +45,7 @@ impl RoomState { /// With the `unstable-unspecified` feature, this method doesn't take any parameters. /// See [matrix-spec#374](https://github.com/matrix-org/matrix-spec/issues/374). pub fn new(origin: String) -> Self { - Self { origin, auth_chain: Vec::new(), state: Vec::new() } + Self { origin, auth_chain: Vec::new(), state: Vec::new(), event: None } } #[cfg(feature = "unstable-unspecified")] @@ -47,6 +54,6 @@ impl RoomState { /// Without the `unstable-unspecified` feature, this method takes a parameter for the origin /// See [matrix-spec#374](https://github.com/matrix-org/matrix-spec/issues/374). pub fn new() -> Self { - Self { auth_chain: Vec::new(), state: Vec::new() } + Self { auth_chain: Vec::new(), state: Vec::new(), event: None } } } diff --git a/crates/ruma-federation-api/src/serde/v1_pdu.rs b/crates/ruma-federation-api/src/serde/v1_pdu.rs index 2591a762..bff8dcf6 100644 --- a/crates/ruma-federation-api/src/serde/v1_pdu.rs +++ b/crates/ruma-federation-api/src/serde/v1_pdu.rs @@ -87,16 +87,21 @@ mod tests { } ]); - let RoomState { origin, auth_chain, state } = deserialize(response).unwrap(); + let RoomState { origin, auth_chain, state, event } = deserialize(response).unwrap(); assert_eq!(origin, "example.com"); assert_matches!(auth_chain.as_slice(), []); assert_matches!(state.as_slice(), []); + assert_matches!(event, None); } #[test] fn serialize_response() { - let room_state = - RoomState { origin: "matrix.org".into(), auth_chain: Vec::new(), state: Vec::new() }; + let room_state = RoomState { + origin: "matrix.org".into(), + auth_chain: Vec::new(), + state: Vec::new(), + event: None, + }; let serialized = serialize(&room_state, serde_json::value::Serializer).unwrap(); let expected = to_json_value(&json!( @@ -142,9 +147,10 @@ mod tests { #[test] fn too_long_array() { let json = json!([200, { "origin": "", "auth_chain": [], "state": [] }, 200]); - let RoomState { origin, auth_chain, state } = deserialize(json).unwrap(); + let RoomState { origin, auth_chain, state, event } = deserialize(json).unwrap(); assert_eq!(origin, ""); assert_matches!(auth_chain.as_slice(), []); assert_matches!(state.as_slice(), []); + assert_matches!(event, None); } }