Skip to content

Commit

Permalink
events: Allow the url in m.room.avatar to be null / missing
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jplatte committed Nov 23, 2020
1 parent 0ae0a89 commit ee4280c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ruma-events/src/room/avatar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,32 @@ pub type AvatarEvent = StateEvent<AvatarEventContent>;
/// 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.
#[serde(skip_serializing_if = "Option::is_none")]
pub info: Option<Box<ImageInfo>>,

/// 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<String>,
}

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()
}
}

0 comments on commit ee4280c

Please sign in to comment.