diff --git a/crates/ruma-common/src/events/room/avatar.rs b/crates/ruma-common/src/events/room/avatar.rs index 8975b62b..395711ee 100644 --- a/crates/ruma-common/src/events/room/avatar.rs +++ b/crates/ruma-common/src/events/room/avatar.rs @@ -14,9 +14,8 @@ use crate::MxcUri; /// A picture that is associated with the room. /// /// This can be displayed alongside the room information. -#[derive(Clone, Debug, Deserialize, Serialize, EventContent)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] -#[cfg_attr(feature = "unstable-pre-spec", derive(Default))] #[ruma_event(type = "m.room.avatar", kind = State)] pub struct RoomAvatarEventContent { /// Information about the avatar image. @@ -24,35 +23,11 @@ pub struct RoomAvatarEventContent { pub info: Option>, /// URL of the avatar image. - /// - /// With the `unstable-pre-spec` feature, this field is optional. - /// See [matrix-spec#471](https://github.com/matrix-org/matrix-spec/issues/471). - #[cfg(not(feature = "unstable-pre-spec"))] - pub url: Box, - - /// URL of the avatar image. - /// - /// Without the `unstable-pre-spec` feature, this field is not optional. - /// See [matrix-spec#471](https://github.com/matrix-org/matrix-spec/issues/471). - #[cfg(feature = "unstable-pre-spec")] pub url: Option>, } impl RoomAvatarEventContent { - /// Create an `RoomAvatarEventContent` from the given image URL. - /// - /// With the `unstable-pre-spec` feature, this method takes no parameters. - /// See [matrix-spec#471](https://github.com/matrix-org/matrix-spec/issues/471). - #[cfg(not(feature = "unstable-pre-spec"))] - pub fn new(url: Box) -> Self { - Self { info: None, url } - } - /// Create an empty `RoomAvatarEventContent`. - /// - /// Without the `unstable-pre-spec` feature, this method takes an `MxcUri`. - /// See [matrix-spec#471](https://github.com/matrix-org/matrix-spec/issues/471). - #[cfg(feature = "unstable-pre-spec")] pub fn new() -> Self { Self::default() } diff --git a/crates/ruma-common/tests/events/state_event.rs b/crates/ruma-common/tests/events/state_event.rs index 89f60c71..cdee1456 100644 --- a/crates/ruma-common/tests/events/state_event.rs +++ b/crates/ruma-common/tests/events/state_event.rs @@ -192,17 +192,12 @@ fn deserialize_avatar_without_prev_content() { "type": "m.room.avatar" }); - let expected_url = mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs").to_owned(); - - #[cfg(feature = "unstable-pre-spec")] - let expected_url = Some(expected_url); - assert_matches!( from_json_value::(json_data).unwrap(), AnyStateEvent::RoomAvatar(StateEvent { content: RoomAvatarEventContent { info: Some(info), - url, + url: Some(url), .. }, event_id, @@ -245,7 +240,7 @@ fn deserialize_avatar_without_prev_content() { && thumbnail_url == mxc_uri!("mxc://matrix.org/98irRSS23srs") ) ) - && url == expected_url + && url == mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs") && unsigned.is_empty() ); } diff --git a/crates/ruma-common/tests/events/stripped.rs b/crates/ruma-common/tests/events/stripped.rs index 0fd7cca7..552c57f9 100644 --- a/crates/ruma-common/tests/events/stripped.rs +++ b/crates/ruma-common/tests/events/stripped.rs @@ -99,17 +99,13 @@ fn deserialize_stripped_state_events() { match event { AnyStrippedStateEvent::RoomAvatar(event) => { let image_info = event.content.info.unwrap(); - let expected_url = mxc_uri!("mxc://example.com/iMag3"); - - #[cfg(feature = "unstable-pre-spec")] - let expected_url = Some(expected_url.to_owned()); assert_eq!(image_info.height.unwrap(), uint!(128)); assert_eq!(image_info.width.unwrap(), uint!(128)); assert_eq!(image_info.mimetype.unwrap(), "image/jpeg"); assert_eq!(image_info.size.unwrap(), uint!(1024)); assert_eq!(image_info.thumbnail_info.unwrap().size.unwrap(), uint!(32)); - assert_eq!(event.content.url, expected_url); + assert_eq!(event.content.url.unwrap(), mxc_uri!("mxc://example.com/iMag3")); assert_eq!(event.state_key, ""); assert_eq!(event.sender.to_string(), "@example:localhost"); }