From ee029901d7c2efea3e0840935525c1ee0bddcf94 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 28 Mar 2022 12:19:16 +0200 Subject: [PATCH] events: Spell out 'source' (don't use 'src' abbreviation) --- crates/ruma-common/src/events/room.rs | 6 +-- crates/ruma-common/src/events/room/message.rs | 48 ++++++++++++------- ...src_serde.rs => thumbnail_source_serde.rs} | 28 +++++------ .../ruma-common/tests/events/message_event.rs | 4 +- .../ruma-common/tests/events/room_message.rs | 2 +- 5 files changed, 50 insertions(+), 38 deletions(-) rename crates/ruma-common/src/events/room/{thumbnail_src_serde.rs => thumbnail_source_serde.rs} (88%) diff --git a/crates/ruma-common/src/events/room.rs b/crates/ruma-common/src/events/room.rs index 170f3461..85952102 100644 --- a/crates/ruma-common/src/events/room.rs +++ b/crates/ruma-common/src/events/room.rs @@ -29,7 +29,7 @@ pub mod power_levels; pub mod redaction; pub mod server_acl; pub mod third_party_invite; -mod thumbnail_src_serde; +mod thumbnail_source_serde; pub mod tombstone; pub mod topic; @@ -71,8 +71,8 @@ pub struct ImageInfo { pub thumbnail_info: Option>, /// The source of the thumbnail of the image. - #[serde(flatten, with = "thumbnail_src_serde", skip_serializing_if = "Option::is_none")] - pub thumbnail_src: Option, + #[serde(flatten, with = "thumbnail_source_serde", skip_serializing_if = "Option::is_none")] + pub thumbnail_source: Option, /// The [BlurHash](https://blurha.sh) for this image. /// diff --git a/crates/ruma-common/src/events/room/message.rs b/crates/ruma-common/src/events/room/message.rs index 829bb3c2..aed49bc7 100644 --- a/crates/ruma-common/src/events/room/message.rs +++ b/crates/ruma-common/src/events/room/message.rs @@ -476,7 +476,7 @@ pub struct AudioMessageEventContent { /// The source of the audio clip. #[serde(flatten)] - pub src: MediaSource, + pub source: MediaSource, /// Metadata for the audio clip referred to in `url`. #[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 /// optional extra info. pub fn plain(body: String, url: Box, info: Option>) -> 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 /// file. 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. #[serde(flatten)] - pub src: MediaSource, + pub source: MediaSource, /// Metadata about the file referred to in `url`. #[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 /// optional extra info. pub fn plain(body: String, url: Box, info: Option>) -> 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 /// file. 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>, /// The source of the thumbnail of the file. - #[serde(flatten, with = "super::thumbnail_src_serde", skip_serializing_if = "Option::is_none")] - pub thumbnail_src: Option, + #[serde( + flatten, + with = "super::thumbnail_source_serde", + skip_serializing_if = "Option::is_none" + )] + pub thumbnail_source: Option, } impl FileInfo { @@ -671,7 +675,7 @@ pub struct ImageMessageEventContent { /// The source of the image. #[serde(flatten)] - pub src: MediaSource, + pub source: MediaSource, /// Metadata about the image referred to in `url`. #[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 /// optional extra info. pub fn plain(body: String, url: Box, info: Option>) -> 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 /// file. 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)] pub struct LocationInfo { /// The URL to a thumbnail of the location. - #[serde(flatten, with = "super::thumbnail_src_serde", skip_serializing_if = "Option::is_none")] - pub thumbnail_src: Option, + #[serde( + flatten, + with = "super::thumbnail_source_serde", + skip_serializing_if = "Option::is_none" + )] + pub thumbnail_source: Option, /// Metadata about the image referred to in `thumbnail_src. #[serde(skip_serializing_if = "Option::is_none")] @@ -1016,7 +1024,7 @@ pub struct VideoMessageEventContent { /// The source of the video clip. #[serde(flatten)] - pub src: MediaSource, + pub source: MediaSource, /// Metadata about the video clip referred to in `url`. #[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 /// optional extra info. pub fn plain(body: String, url: Box, info: Option>) -> 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 /// file. 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>, /// The source of the thumbnail of the video clip. - #[serde(flatten, with = "super::thumbnail_src_serde", skip_serializing_if = "Option::is_none")] - pub thumbnail_src: Option, + #[serde( + flatten, + with = "super::thumbnail_source_serde", + skip_serializing_if = "Option::is_none" + )] + pub thumbnail_source: Option, /// The [BlurHash](https://blurha.sh) for this video. /// diff --git a/crates/ruma-common/src/events/room/thumbnail_src_serde.rs b/crates/ruma-common/src/events/room/thumbnail_source_serde.rs similarity index 88% rename from crates/ruma-common/src/events/room/thumbnail_src_serde.rs rename to crates/ruma-common/src/events/room/thumbnail_source_serde.rs index 87781607..e39872d4 100644 --- a/crates/ruma-common/src/events/room/thumbnail_src_serde.rs +++ b/crates/ruma-common/src/events/room/thumbnail_source_serde.rs @@ -11,13 +11,13 @@ use crate::MxcUri; use super::{EncryptedFile, MediaSource}; /// Serializes a MediaSource to a thumbnail source. -pub fn serialize(src: &Option, serializer: S) -> Result +pub fn serialize(source: &Option, serializer: S) -> Result where S: Serializer, { - if let Some(src) = src { + if let Some(source) = source { let mut st = serializer.serialize_struct("ThumbnailSource", 1)?; - match src { + match source { MediaSource::Plain(url) => st.serialize_field("thumbnail_url", url)?, MediaSource::Encrypted(file) => st.serialize_field("thumbnail_file", file)?, } @@ -47,8 +47,8 @@ enum ThumbnailSource { } impl From for MediaSource { - fn from(src: ThumbnailSource) -> Self { - match src { + fn from(source: ThumbnailSource) -> Self { + match source { ThumbnailSource::Plain(url) => Self::Plain(url), ThumbnailSource::Encrypted(file) => Self::Encrypted(file), } @@ -70,7 +70,7 @@ mod tests { #[derive(Clone, Debug, Deserialize, Serialize)] struct ThumbnailSourceTest { #[serde(flatten, with = "super", skip_serializing_if = "Option::is_none")] - src: Option, + source: Option, } #[test] @@ -79,7 +79,7 @@ mod tests { assert_matches!( serde_json::from_value::(json).unwrap(), - ThumbnailSourceTest { src: Some(MediaSource::Plain(url)) } + ThumbnailSourceTest { source: Some(MediaSource::Plain(url)) } if url == "mxc://notareal.hs/abcdef" ); } @@ -106,7 +106,7 @@ mod tests { assert_matches!( serde_json::from_value::(json).unwrap(), - ThumbnailSourceTest { src: Some(MediaSource::Encrypted(file)) } + ThumbnailSourceTest { source: Some(MediaSource::Encrypted(file)) } if file.url == "mxc://notareal.hs/abcdef" ); } @@ -117,7 +117,7 @@ mod tests { assert_matches!( serde_json::from_value::(json).unwrap(), - ThumbnailSourceTest { src: None } + ThumbnailSourceTest { source: None } ); } @@ -127,7 +127,7 @@ mod tests { assert_matches!( serde_json::from_value::(json).unwrap(), - ThumbnailSourceTest { src: None } + ThumbnailSourceTest { source: None } ); } @@ -137,14 +137,14 @@ mod tests { assert_matches!( serde_json::from_value::(json).unwrap(), - ThumbnailSourceTest { src: None } + ThumbnailSourceTest { source: None } ); } #[test] fn serialize_plain() { 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!( serde_json::to_value(&request).unwrap(), @@ -155,7 +155,7 @@ mod tests { #[test] fn serialize_encrypted() { let request = ThumbnailSourceTest { - src: Some(MediaSource::Encrypted(Box::new( + source: Some(MediaSource::Encrypted(Box::new( EncryptedFileInit { url: mxc_uri!("mxc://notareal.hs/abcdef").to_owned(), key: JsonWebKeyInit { @@ -201,7 +201,7 @@ mod tests { #[test] fn serialize_none() { - let request = ThumbnailSourceTest { src: None }; + let request = ThumbnailSourceTest { source: None }; assert_eq!(serde_json::to_value(&request).unwrap(), json!({})); } } diff --git a/crates/ruma-common/tests/events/message_event.rs b/crates/ruma-common/tests/events/message_event.rs index 9ff44a10..38ef9db9 100644 --- a/crates/ruma-common/tests/events/message_event.rs +++ b/crates/ruma-common/tests/events/message_event.rs @@ -32,7 +32,7 @@ fn message_serialize_sticker() { mimetype: Some("image/png".into()), 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(), ), @@ -184,7 +184,7 @@ fn deserialize_message_sticker() { mimetype: Some(mimetype), size, thumbnail_info: Some(thumbnail_info), - thumbnail_src: Some(MediaSource::Plain(thumbnail_url)), + thumbnail_source: Some(MediaSource::Plain(thumbnail_url)), #[cfg(feature = "unstable-msc2448")] blurhash: None, .. diff --git a/crates/ruma-common/tests/events/room_message.rs b/crates/ruma-common/tests/events/room_message.rs index 3f595f32..e12163d6 100644 --- a/crates/ruma-common/tests/events/room_message.rs +++ b/crates/ruma-common/tests/events/room_message.rs @@ -446,7 +446,7 @@ fn content_deserialization() { msgtype: MessageType::Audio(AudioMessageEventContent { body, info: None, - src: MediaSource::Plain(url), + source: MediaSource::Plain(url), .. }), ..