events: Spell out 'source' (don't use 'src' abbreviation)

This commit is contained in:
Jonas Platte 2022-03-28 12:19:16 +02:00
parent c9b353a384
commit ee029901d7
No known key found for this signature in database
GPG Key ID: BBA95679259D342F
5 changed files with 50 additions and 38 deletions

View File

@ -29,7 +29,7 @@ pub mod power_levels;
pub mod redaction; pub mod redaction;
pub mod server_acl; pub mod server_acl;
pub mod third_party_invite; pub mod third_party_invite;
mod thumbnail_src_serde; mod thumbnail_source_serde;
pub mod tombstone; pub mod tombstone;
pub mod topic; pub mod topic;
@ -71,8 +71,8 @@ pub struct ImageInfo {
pub thumbnail_info: Option<Box<ThumbnailInfo>>, pub thumbnail_info: Option<Box<ThumbnailInfo>>,
/// The source of the thumbnail of the image. /// The source of the thumbnail of the image.
#[serde(flatten, with = "thumbnail_src_serde", skip_serializing_if = "Option::is_none")] #[serde(flatten, with = "thumbnail_source_serde", skip_serializing_if = "Option::is_none")]
pub thumbnail_src: Option<MediaSource>, pub thumbnail_source: Option<MediaSource>,
/// The [BlurHash](https://blurha.sh) for this image. /// The [BlurHash](https://blurha.sh) for this image.
/// ///

View File

@ -476,7 +476,7 @@ pub struct AudioMessageEventContent {
/// The source of the audio clip. /// The source of the audio clip.
#[serde(flatten)] #[serde(flatten)]
pub src: MediaSource, pub source: MediaSource,
/// Metadata for the audio clip referred to in `url`. /// Metadata for the audio clip referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -487,13 +487,13 @@ impl AudioMessageEventContent {
/// Creates a new non-encrypted `RoomAudioMessageEventContent` with the given body, url and /// Creates a new non-encrypted `RoomAudioMessageEventContent` with the given body, url and
/// optional extra info. /// optional extra info.
pub fn plain(body: String, url: Box<MxcUri>, info: Option<Box<AudioInfo>>) -> Self { pub fn plain(body: String, url: Box<MxcUri>, info: Option<Box<AudioInfo>>) -> Self {
Self { body, src: MediaSource::Plain(url), info } Self { body, source: MediaSource::Plain(url), info }
} }
/// Creates a new encrypted `RoomAudioMessageEventContent` with the given body and encrypted /// Creates a new encrypted `RoomAudioMessageEventContent` with the given body and encrypted
/// file. /// file.
pub fn encrypted(body: String, file: EncryptedFile) -> Self { pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self { body, src: MediaSource::Encrypted(Box::new(file)), info: None } Self { body, source: MediaSource::Encrypted(Box::new(file)), info: None }
} }
} }
@ -609,7 +609,7 @@ pub struct FileMessageEventContent {
/// The source of the file. /// The source of the file.
#[serde(flatten)] #[serde(flatten)]
pub src: MediaSource, pub source: MediaSource,
/// Metadata about the file referred to in `url`. /// Metadata about the file referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -620,13 +620,13 @@ impl FileMessageEventContent {
/// Creates a new non-encrypted `RoomFileMessageEventContent` with the given body, url and /// Creates a new non-encrypted `RoomFileMessageEventContent` with the given body, url and
/// optional extra info. /// optional extra info.
pub fn plain(body: String, url: Box<MxcUri>, info: Option<Box<FileInfo>>) -> Self { pub fn plain(body: String, url: Box<MxcUri>, info: Option<Box<FileInfo>>) -> Self {
Self { body, filename: None, src: MediaSource::Plain(url), info } Self { body, filename: None, source: MediaSource::Plain(url), info }
} }
/// Creates a new encrypted `RoomFileMessageEventContent` with the given body and encrypted /// Creates a new encrypted `RoomFileMessageEventContent` with the given body and encrypted
/// file. /// file.
pub fn encrypted(body: String, file: EncryptedFile) -> Self { pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self { body, filename: None, src: MediaSource::Encrypted(Box::new(file)), info: None } Self { body, filename: None, source: MediaSource::Encrypted(Box::new(file)), info: None }
} }
} }
@ -647,8 +647,12 @@ pub struct FileInfo {
pub thumbnail_info: Option<Box<ThumbnailInfo>>, pub thumbnail_info: Option<Box<ThumbnailInfo>>,
/// The source of the thumbnail of the file. /// The source of the thumbnail of the file.
#[serde(flatten, with = "super::thumbnail_src_serde", skip_serializing_if = "Option::is_none")] #[serde(
pub thumbnail_src: Option<MediaSource>, flatten,
with = "super::thumbnail_source_serde",
skip_serializing_if = "Option::is_none"
)]
pub thumbnail_source: Option<MediaSource>,
} }
impl FileInfo { impl FileInfo {
@ -671,7 +675,7 @@ pub struct ImageMessageEventContent {
/// The source of the image. /// The source of the image.
#[serde(flatten)] #[serde(flatten)]
pub src: MediaSource, pub source: MediaSource,
/// Metadata about the image referred to in `url`. /// Metadata about the image referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -682,13 +686,13 @@ impl ImageMessageEventContent {
/// Creates a new non-encrypted `RoomImageMessageEventContent` with the given body, url and /// Creates a new non-encrypted `RoomImageMessageEventContent` with the given body, url and
/// optional extra info. /// optional extra info.
pub fn plain(body: String, url: Box<MxcUri>, info: Option<Box<ImageInfo>>) -> Self { pub fn plain(body: String, url: Box<MxcUri>, info: Option<Box<ImageInfo>>) -> Self {
Self { body, src: MediaSource::Plain(url), info } Self { body, source: MediaSource::Plain(url), info }
} }
/// Creates a new encrypted `RoomImageMessageEventContent` with the given body and encrypted /// Creates a new encrypted `RoomImageMessageEventContent` with the given body and encrypted
/// file. /// file.
pub fn encrypted(body: String, file: EncryptedFile) -> Self { pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self { body, src: MediaSource::Encrypted(Box::new(file)), info: None } Self { body, source: MediaSource::Encrypted(Box::new(file)), info: None }
} }
} }
@ -721,8 +725,12 @@ impl LocationMessageEventContent {
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct LocationInfo { pub struct LocationInfo {
/// The URL to a thumbnail of the location. /// The URL to a thumbnail of the location.
#[serde(flatten, with = "super::thumbnail_src_serde", skip_serializing_if = "Option::is_none")] #[serde(
pub thumbnail_src: Option<MediaSource>, flatten,
with = "super::thumbnail_source_serde",
skip_serializing_if = "Option::is_none"
)]
pub thumbnail_source: Option<MediaSource>,
/// Metadata about the image referred to in `thumbnail_src. /// Metadata about the image referred to in `thumbnail_src.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -1016,7 +1024,7 @@ pub struct VideoMessageEventContent {
/// The source of the video clip. /// The source of the video clip.
#[serde(flatten)] #[serde(flatten)]
pub src: MediaSource, pub source: MediaSource,
/// Metadata about the video clip referred to in `url`. /// Metadata about the video clip referred to in `url`.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -1027,13 +1035,13 @@ impl VideoMessageEventContent {
/// Creates a new non-encrypted `RoomVideoMessageEventContent` with the given body, url and /// Creates a new non-encrypted `RoomVideoMessageEventContent` with the given body, url and
/// optional extra info. /// optional extra info.
pub fn plain(body: String, url: Box<MxcUri>, info: Option<Box<VideoInfo>>) -> Self { pub fn plain(body: String, url: Box<MxcUri>, info: Option<Box<VideoInfo>>) -> Self {
Self { body, src: MediaSource::Plain(url), info } Self { body, source: MediaSource::Plain(url), info }
} }
/// Creates a new encrypted `RoomVideoMessageEventContent` with the given body and encrypted /// Creates a new encrypted `RoomVideoMessageEventContent` with the given body and encrypted
/// file. /// file.
pub fn encrypted(body: String, file: EncryptedFile) -> Self { pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self { body, src: MediaSource::Encrypted(Box::new(file)), info: None } Self { body, source: MediaSource::Encrypted(Box::new(file)), info: None }
} }
} }
@ -1070,8 +1078,12 @@ pub struct VideoInfo {
pub thumbnail_info: Option<Box<ThumbnailInfo>>, pub thumbnail_info: Option<Box<ThumbnailInfo>>,
/// The source of the thumbnail of the video clip. /// The source of the thumbnail of the video clip.
#[serde(flatten, with = "super::thumbnail_src_serde", skip_serializing_if = "Option::is_none")] #[serde(
pub thumbnail_src: Option<MediaSource>, flatten,
with = "super::thumbnail_source_serde",
skip_serializing_if = "Option::is_none"
)]
pub thumbnail_source: Option<MediaSource>,
/// The [BlurHash](https://blurha.sh) for this video. /// The [BlurHash](https://blurha.sh) for this video.
/// ///

View File

@ -11,13 +11,13 @@ use crate::MxcUri;
use super::{EncryptedFile, MediaSource}; use super::{EncryptedFile, MediaSource};
/// Serializes a MediaSource to a thumbnail source. /// Serializes a MediaSource to a thumbnail source.
pub fn serialize<S>(src: &Option<MediaSource>, serializer: S) -> Result<S::Ok, S::Error> pub fn serialize<S>(source: &Option<MediaSource>, serializer: S) -> Result<S::Ok, S::Error>
where where
S: Serializer, S: Serializer,
{ {
if let Some(src) = src { if let Some(source) = source {
let mut st = serializer.serialize_struct("ThumbnailSource", 1)?; let mut st = serializer.serialize_struct("ThumbnailSource", 1)?;
match src { match source {
MediaSource::Plain(url) => st.serialize_field("thumbnail_url", url)?, MediaSource::Plain(url) => st.serialize_field("thumbnail_url", url)?,
MediaSource::Encrypted(file) => st.serialize_field("thumbnail_file", file)?, MediaSource::Encrypted(file) => st.serialize_field("thumbnail_file", file)?,
} }
@ -47,8 +47,8 @@ enum ThumbnailSource {
} }
impl From<ThumbnailSource> for MediaSource { impl From<ThumbnailSource> for MediaSource {
fn from(src: ThumbnailSource) -> Self { fn from(source: ThumbnailSource) -> Self {
match src { match source {
ThumbnailSource::Plain(url) => Self::Plain(url), ThumbnailSource::Plain(url) => Self::Plain(url),
ThumbnailSource::Encrypted(file) => Self::Encrypted(file), ThumbnailSource::Encrypted(file) => Self::Encrypted(file),
} }
@ -70,7 +70,7 @@ mod tests {
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
struct ThumbnailSourceTest { struct ThumbnailSourceTest {
#[serde(flatten, with = "super", skip_serializing_if = "Option::is_none")] #[serde(flatten, with = "super", skip_serializing_if = "Option::is_none")]
src: Option<MediaSource>, source: Option<MediaSource>,
} }
#[test] #[test]
@ -79,7 +79,7 @@ mod tests {
assert_matches!( assert_matches!(
serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(), serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(),
ThumbnailSourceTest { src: Some(MediaSource::Plain(url)) } ThumbnailSourceTest { source: Some(MediaSource::Plain(url)) }
if url == "mxc://notareal.hs/abcdef" if url == "mxc://notareal.hs/abcdef"
); );
} }
@ -106,7 +106,7 @@ mod tests {
assert_matches!( assert_matches!(
serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(), serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(),
ThumbnailSourceTest { src: Some(MediaSource::Encrypted(file)) } ThumbnailSourceTest { source: Some(MediaSource::Encrypted(file)) }
if file.url == "mxc://notareal.hs/abcdef" if file.url == "mxc://notareal.hs/abcdef"
); );
} }
@ -117,7 +117,7 @@ mod tests {
assert_matches!( assert_matches!(
serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(), serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(),
ThumbnailSourceTest { src: None } ThumbnailSourceTest { source: None }
); );
} }
@ -127,7 +127,7 @@ mod tests {
assert_matches!( assert_matches!(
serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(), serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(),
ThumbnailSourceTest { src: None } ThumbnailSourceTest { source: None }
); );
} }
@ -137,14 +137,14 @@ mod tests {
assert_matches!( assert_matches!(
serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(), serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(),
ThumbnailSourceTest { src: None } ThumbnailSourceTest { source: None }
); );
} }
#[test] #[test]
fn serialize_plain() { fn serialize_plain() {
let request = ThumbnailSourceTest { let request = ThumbnailSourceTest {
src: Some(MediaSource::Plain(mxc_uri!("mxc://notareal.hs/abcdef").into())), source: Some(MediaSource::Plain(mxc_uri!("mxc://notareal.hs/abcdef").into())),
}; };
assert_eq!( assert_eq!(
serde_json::to_value(&request).unwrap(), serde_json::to_value(&request).unwrap(),
@ -155,7 +155,7 @@ mod tests {
#[test] #[test]
fn serialize_encrypted() { fn serialize_encrypted() {
let request = ThumbnailSourceTest { let request = ThumbnailSourceTest {
src: Some(MediaSource::Encrypted(Box::new( source: Some(MediaSource::Encrypted(Box::new(
EncryptedFileInit { EncryptedFileInit {
url: mxc_uri!("mxc://notareal.hs/abcdef").to_owned(), url: mxc_uri!("mxc://notareal.hs/abcdef").to_owned(),
key: JsonWebKeyInit { key: JsonWebKeyInit {
@ -201,7 +201,7 @@ mod tests {
#[test] #[test]
fn serialize_none() { fn serialize_none() {
let request = ThumbnailSourceTest { src: None }; let request = ThumbnailSourceTest { source: None };
assert_eq!(serde_json::to_value(&request).unwrap(), json!({})); assert_eq!(serde_json::to_value(&request).unwrap(), json!({}));
} }
} }

View File

@ -32,7 +32,7 @@ fn message_serialize_sticker() {
mimetype: Some("image/png".into()), mimetype: Some("image/png".into()),
size: UInt::new(82595), size: UInt::new(82595),
}))), }))),
thumbnail_src: Some(MediaSource::Plain(mxc_uri!("mxc://matrix.org/irsns989Rrsn").to_owned())), thumbnail_source: Some(MediaSource::Plain(mxc_uri!("mxc://matrix.org/irsns989Rrsn").to_owned())),
}), }),
mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs").to_owned(), mxc_uri!("mxc://matrix.org/rnsldl8srs98IRrs").to_owned(),
), ),
@ -184,7 +184,7 @@ fn deserialize_message_sticker() {
mimetype: Some(mimetype), mimetype: Some(mimetype),
size, size,
thumbnail_info: Some(thumbnail_info), thumbnail_info: Some(thumbnail_info),
thumbnail_src: Some(MediaSource::Plain(thumbnail_url)), thumbnail_source: Some(MediaSource::Plain(thumbnail_url)),
#[cfg(feature = "unstable-msc2448")] #[cfg(feature = "unstable-msc2448")]
blurhash: None, blurhash: None,
.. ..

View File

@ -446,7 +446,7 @@ fn content_deserialization() {
msgtype: MessageType::Audio(AudioMessageEventContent { msgtype: MessageType::Audio(AudioMessageEventContent {
body, body,
info: None, info: None,
src: MediaSource::Plain(url), source: MediaSource::Plain(url),
.. ..
}), }),
.. ..