ruma_events/room/
avatar.rs

1//! Types for the [`m.room.avatar`] event.
2//!
3//! [`m.room.avatar`]: https://spec.matrix.org/latest/client-server-api/#mroomavatar
4
5use js_int::UInt;
6#[cfg(feature = "unstable-msc2448")]
7use ruma_common::serde::Base64;
8use ruma_common::OwnedMxcUri;
9use ruma_macros::EventContent;
10use serde::{Deserialize, Serialize};
11
12use super::ThumbnailInfo;
13use crate::EmptyStateKey;
14
15/// The content of an `m.room.avatar` event.
16///
17/// A picture that is associated with the room.
18///
19/// This can be displayed alongside the room information.
20#[derive(Clone, Debug, Default, Deserialize, Serialize, EventContent)]
21#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
22#[ruma_event(type = "m.room.avatar", kind = State, state_key_type = EmptyStateKey)]
23pub struct RoomAvatarEventContent {
24    /// Information about the avatar image.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub info: Option<Box<ImageInfo>>,
27
28    /// URL of the avatar image.
29    pub url: Option<OwnedMxcUri>,
30}
31
32impl RoomAvatarEventContent {
33    /// Create an empty `RoomAvatarEventContent`.
34    pub fn new() -> Self {
35        Self::default()
36    }
37}
38
39/// Metadata about an image (specific to avatars).
40#[derive(Clone, Debug, Default, Deserialize, Serialize)]
41#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
42pub struct ImageInfo {
43    /// The height of the image in pixels.
44    #[serde(rename = "h", skip_serializing_if = "Option::is_none")]
45    pub height: Option<UInt>,
46
47    /// The width of the image in pixels.
48    #[serde(rename = "w", skip_serializing_if = "Option::is_none")]
49    pub width: Option<UInt>,
50
51    /// The MIME type of the image, e.g. "image/png."
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub mimetype: Option<String>,
54
55    /// The file size of the image in bytes.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub size: Option<UInt>,
58
59    /// Metadata about the image referred to in `thumbnail_url`.
60    #[serde(skip_serializing_if = "Option::is_none")]
61    pub thumbnail_info: Option<Box<ThumbnailInfo>>,
62
63    /// The URL to the thumbnail of the image.
64    #[serde(skip_serializing_if = "Option::is_none")]
65    pub thumbnail_url: Option<OwnedMxcUri>,
66
67    /// The [BlurHash](https://blurha.sh) for this image.
68    ///
69    /// This uses the unstable prefix in
70    /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448).
71    #[cfg(feature = "unstable-msc2448")]
72    #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")]
73    pub blurhash: Option<String>,
74
75    /// The [ThumbHash](https://evanw.github.io/thumbhash/) for this image.
76    ///
77    /// This uses the unstable prefix in
78    /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448).
79    #[cfg(feature = "unstable-msc2448")]
80    #[serde(rename = "xyz.amorgan.thumbhash", skip_serializing_if = "Option::is_none")]
81    pub thumbhash: Option<Base64>,
82}
83
84impl ImageInfo {
85    /// Create a new `ImageInfo` with all fields set to `None`.
86    pub fn new() -> Self {
87        Self::default()
88    }
89}