events: Make m.room.avatar url optional, always

Removes the feature gate because this has been clarified to be right
in the spec: https://github.com/matrix-org/matrix-spec/pull/987
This commit is contained in:
Jonas Platte 2022-03-22 14:45:52 +01:00
parent eb515046d7
commit f0710fdf1b
No known key found for this signature in database
GPG Key ID: BBA95679259D342F
3 changed files with 4 additions and 38 deletions

View File

@ -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<Box<ImageInfo>>,
/// 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<MxcUri>,
/// 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<Box<MxcUri>>,
}
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<MxcUri>) -> 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()
}

View File

@ -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::<AnyStateEvent>(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()
);
}

View File

@ -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");
}