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:
parent
eb515046d7
commit
f0710fdf1b
@ -14,9 +14,8 @@ use crate::MxcUri;
|
|||||||
/// A picture that is associated with the room.
|
/// A picture that is associated with the room.
|
||||||
///
|
///
|
||||||
/// This can be displayed alongside the room information.
|
/// 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(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
|
||||||
#[cfg_attr(feature = "unstable-pre-spec", derive(Default))]
|
|
||||||
#[ruma_event(type = "m.room.avatar", kind = State)]
|
#[ruma_event(type = "m.room.avatar", kind = State)]
|
||||||
pub struct RoomAvatarEventContent {
|
pub struct RoomAvatarEventContent {
|
||||||
/// Information about the avatar image.
|
/// Information about the avatar image.
|
||||||
@ -24,35 +23,11 @@ pub struct RoomAvatarEventContent {
|
|||||||
pub info: Option<Box<ImageInfo>>,
|
pub info: Option<Box<ImageInfo>>,
|
||||||
|
|
||||||
/// URL of the avatar image.
|
/// 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>>,
|
pub url: Option<Box<MxcUri>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RoomAvatarEventContent {
|
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`.
|
/// 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 {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
@ -192,17 +192,12 @@ fn deserialize_avatar_without_prev_content() {
|
|||||||
"type": "m.room.avatar"
|
"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!(
|
assert_matches!(
|
||||||
from_json_value::<AnyStateEvent>(json_data).unwrap(),
|
from_json_value::<AnyStateEvent>(json_data).unwrap(),
|
||||||
AnyStateEvent::RoomAvatar(StateEvent {
|
AnyStateEvent::RoomAvatar(StateEvent {
|
||||||
content: RoomAvatarEventContent {
|
content: RoomAvatarEventContent {
|
||||||
info: Some(info),
|
info: Some(info),
|
||||||
url,
|
url: Some(url),
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
event_id,
|
event_id,
|
||||||
@ -245,7 +240,7 @@ fn deserialize_avatar_without_prev_content() {
|
|||||||
&& thumbnail_url == mxc_uri!("mxc://matrix.org/98irRSS23srs")
|
&& thumbnail_url == mxc_uri!("mxc://matrix.org/98irRSS23srs")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
&& url == expected_url
|
&& url == mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs")
|
||||||
&& unsigned.is_empty()
|
&& unsigned.is_empty()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -99,17 +99,13 @@ fn deserialize_stripped_state_events() {
|
|||||||
match event {
|
match event {
|
||||||
AnyStrippedStateEvent::RoomAvatar(event) => {
|
AnyStrippedStateEvent::RoomAvatar(event) => {
|
||||||
let image_info = event.content.info.unwrap();
|
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.height.unwrap(), uint!(128));
|
||||||
assert_eq!(image_info.width.unwrap(), uint!(128));
|
assert_eq!(image_info.width.unwrap(), uint!(128));
|
||||||
assert_eq!(image_info.mimetype.unwrap(), "image/jpeg");
|
assert_eq!(image_info.mimetype.unwrap(), "image/jpeg");
|
||||||
assert_eq!(image_info.size.unwrap(), uint!(1024));
|
assert_eq!(image_info.size.unwrap(), uint!(1024));
|
||||||
assert_eq!(image_info.thumbnail_info.unwrap().size.unwrap(), uint!(32));
|
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.state_key, "");
|
||||||
assert_eq!(event.sender.to_string(), "@example:localhost");
|
assert_eq!(event.sender.to_string(), "@example:localhost");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user