events: Allow the url in m.room.avatar to be null / missing

This isn't allowed in any version of the spec, but it's the only way to
unset an avatar and will have to be supported in the future.

C.f. https://github.com/matrix-org/matrix-doc/issues/2006
This commit is contained in:
Jonas Platte 2020-11-23 14:18:41 +01:00
parent 0ae0a89467
commit ee4280cea2
No known key found for this signature in database
GPG Key ID: 7D261D771D915378

View File

@ -14,6 +14,7 @@ pub type AvatarEvent = StateEvent<AvatarEventContent>;
/// The payload for `AvatarEvent`. /// The payload for `AvatarEvent`.
#[derive(Clone, Debug, Deserialize, Serialize, StateEventContent)] #[derive(Clone, Debug, Deserialize, Serialize, StateEventContent)]
#[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")] #[ruma_event(type = "m.room.avatar")]
pub struct AvatarEventContent { pub struct AvatarEventContent {
/// Information about the avatar image. /// Information about the avatar image.
@ -21,12 +22,24 @@ pub struct AvatarEventContent {
pub info: Option<Box<ImageInfo>>, pub info: Option<Box<ImageInfo>>,
/// URL of the avatar image. /// URL of the avatar image.
#[cfg(not(feature = "unstable-pre-spec"))]
pub url: String, pub url: String,
/// URL of the avatar image.
#[cfg(feature = "unstable-pre-spec")]
pub url: Option<String>,
} }
impl AvatarEventContent { impl AvatarEventContent {
/// Create an `AvatarEventContent` from the given image URL. /// Create an `AvatarEventContent` from the given image URL.
#[cfg(not(feature = "unstable-pre-spec"))]
pub fn new(url: String) -> Self { pub fn new(url: String) -> Self {
Self { info: None, url } Self { info: None, url }
} }
/// Create an empty `AvatarEventContent`.
#[cfg(feature = "unstable-pre-spec")]
pub fn new() -> Self {
Self::default()
}
} }