events: Spell out 'source' (don't use 'src' abbreviation)
This commit is contained in:
parent
c9b353a384
commit
ee029901d7
@ -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<Box<ThumbnailInfo>>,
|
||||
|
||||
/// The source of the thumbnail of the image.
|
||||
#[serde(flatten, with = "thumbnail_src_serde", skip_serializing_if = "Option::is_none")]
|
||||
pub thumbnail_src: Option<MediaSource>,
|
||||
#[serde(flatten, with = "thumbnail_source_serde", skip_serializing_if = "Option::is_none")]
|
||||
pub thumbnail_source: Option<MediaSource>,
|
||||
|
||||
/// The [BlurHash](https://blurha.sh) for this image.
|
||||
///
|
||||
|
@ -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<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
|
||||
/// 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<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
|
||||
/// 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<Box<ThumbnailInfo>>,
|
||||
|
||||
/// 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<MediaSource>,
|
||||
#[serde(
|
||||
flatten,
|
||||
with = "super::thumbnail_source_serde",
|
||||
skip_serializing_if = "Option::is_none"
|
||||
)]
|
||||
pub thumbnail_source: Option<MediaSource>,
|
||||
}
|
||||
|
||||
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<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
|
||||
/// 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<MediaSource>,
|
||||
#[serde(
|
||||
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.
|
||||
#[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<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
|
||||
/// 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<Box<ThumbnailInfo>>,
|
||||
|
||||
/// 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<MediaSource>,
|
||||
#[serde(
|
||||
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.
|
||||
///
|
||||
|
@ -11,13 +11,13 @@ use crate::MxcUri;
|
||||
use super::{EncryptedFile, MediaSource};
|
||||
|
||||
/// 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
|
||||
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<ThumbnailSource> 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<MediaSource>,
|
||||
source: Option<MediaSource>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -79,7 +79,7 @@ mod tests {
|
||||
|
||||
assert_matches!(
|
||||
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"
|
||||
);
|
||||
}
|
||||
@ -106,7 +106,7 @@ mod tests {
|
||||
|
||||
assert_matches!(
|
||||
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"
|
||||
);
|
||||
}
|
||||
@ -117,7 +117,7 @@ mod tests {
|
||||
|
||||
assert_matches!(
|
||||
serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(),
|
||||
ThumbnailSourceTest { src: None }
|
||||
ThumbnailSourceTest { source: None }
|
||||
);
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ mod tests {
|
||||
|
||||
assert_matches!(
|
||||
serde_json::from_value::<ThumbnailSourceTest>(json).unwrap(),
|
||||
ThumbnailSourceTest { src: None }
|
||||
ThumbnailSourceTest { source: None }
|
||||
);
|
||||
}
|
||||
|
||||
@ -137,14 +137,14 @@ mod tests {
|
||||
|
||||
assert_matches!(
|
||||
serde_json::from_value::<ThumbnailSourceTest>(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!({}));
|
||||
}
|
||||
}
|
@ -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,
|
||||
..
|
||||
|
@ -446,7 +446,7 @@ fn content_deserialization() {
|
||||
msgtype: MessageType::Audio(AudioMessageEventContent {
|
||||
body,
|
||||
info: None,
|
||||
src: MediaSource::Plain(url),
|
||||
source: MediaSource::Plain(url),
|
||||
..
|
||||
}),
|
||||
..
|
||||
|
Loading…
x
Reference in New Issue
Block a user