From ee4280cea2f8d24c7f747fd57776fe72d50ce744 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 23 Nov 2020 14:18:41 +0100 Subject: [PATCH] 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 --- ruma-events/src/room/avatar.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ruma-events/src/room/avatar.rs b/ruma-events/src/room/avatar.rs index 98efdb3b..79608e52 100644 --- a/ruma-events/src/room/avatar.rs +++ b/ruma-events/src/room/avatar.rs @@ -14,6 +14,7 @@ pub type AvatarEvent = StateEvent; /// The payload for `AvatarEvent`. #[derive(Clone, Debug, Deserialize, Serialize, StateEventContent)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] +#[cfg_attr(feature = "unstable-pre-spec", derive(Default))] #[ruma_event(type = "m.room.avatar")] pub struct AvatarEventContent { /// Information about the avatar image. @@ -21,12 +22,24 @@ pub struct AvatarEventContent { pub info: Option>, /// URL of the avatar image. + #[cfg(not(feature = "unstable-pre-spec"))] pub url: String, + + /// URL of the avatar image. + #[cfg(feature = "unstable-pre-spec")] + pub url: Option, } impl AvatarEventContent { /// Create an `AvatarEventContent` from the given image URL. + #[cfg(not(feature = "unstable-pre-spec"))] pub fn new(url: String) -> Self { Self { info: None, url } } + + /// Create an empty `AvatarEventContent`. + #[cfg(feature = "unstable-pre-spec")] + pub fn new() -> Self { + Self::default() + } }