events: Streamline constructors of media event content structs
This commit is contained in:
parent
59fd881521
commit
c1fa8d9406
@ -26,16 +26,21 @@ pub struct AudioMessageEventContent {
|
||||
}
|
||||
|
||||
impl AudioMessageEventContent {
|
||||
/// Creates a new `AudioMessageEventContent` with the given body and source.
|
||||
pub fn new(body: String, source: MediaSource) -> Self {
|
||||
Self { body, source, info: None }
|
||||
}
|
||||
|
||||
/// Creates a new non-encrypted `AudioMessageEventContent` with the given body, url and
|
||||
/// optional extra info.
|
||||
pub fn plain(body: String, url: OwnedMxcUri, info: Option<Box<AudioInfo>>) -> Self {
|
||||
Self { body, source: MediaSource::Plain(url), info }
|
||||
pub fn plain(body: String, url: OwnedMxcUri) -> Self {
|
||||
Self::new(body, MediaSource::Plain(url))
|
||||
}
|
||||
|
||||
/// Creates a new encrypted `AudioMessageEventContent` with the given body and encrypted
|
||||
/// file.
|
||||
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
||||
Self { body, source: MediaSource::Encrypted(Box::new(file)), info: None }
|
||||
Self::new(body, MediaSource::Encrypted(Box::new(file)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,16 +30,21 @@ pub struct FileMessageEventContent {
|
||||
}
|
||||
|
||||
impl FileMessageEventContent {
|
||||
/// Creates a new `FileMessageEventContent` with the given body and source.
|
||||
pub fn new(body: String, source: MediaSource) -> Self {
|
||||
Self { body, filename: None, source, info: None }
|
||||
}
|
||||
|
||||
/// Creates a new non-encrypted `FileMessageEventContent` with the given body, url and
|
||||
/// optional extra info.
|
||||
pub fn plain(body: String, url: OwnedMxcUri, info: Option<Box<FileInfo>>) -> Self {
|
||||
Self { body, filename: None, source: MediaSource::Plain(url), info }
|
||||
pub fn plain(body: String, url: OwnedMxcUri) -> Self {
|
||||
Self::new(body, MediaSource::Plain(url))
|
||||
}
|
||||
|
||||
/// Creates a new encrypted `FileMessageEventContent` with the given body and encrypted
|
||||
/// file.
|
||||
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
||||
Self { body, filename: None, source: MediaSource::Encrypted(Box::new(file)), info: None }
|
||||
Self::new(body, MediaSource::Encrypted(Box::new(file)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,15 +26,19 @@ pub struct ImageMessageEventContent {
|
||||
}
|
||||
|
||||
impl ImageMessageEventContent {
|
||||
/// Creates a new non-encrypted `ImageMessageEventContent` with the given body, url and
|
||||
/// optional extra info.
|
||||
pub fn plain(body: String, url: OwnedMxcUri, info: Option<Box<ImageInfo>>) -> Self {
|
||||
Self { body, source: MediaSource::Plain(url), info }
|
||||
/// Creates a new `ImageMessageEventContent` with the given body and source.
|
||||
pub fn new(body: String, source: MediaSource) -> Self {
|
||||
Self { body, source, info: None }
|
||||
}
|
||||
|
||||
/// Creates a new non-encrypted `ImageMessageEventContent` with the given body and url.
|
||||
pub fn plain(body: String, url: OwnedMxcUri) -> Self {
|
||||
Self::new(body, MediaSource::Plain(url))
|
||||
}
|
||||
|
||||
/// Creates a new encrypted `ImageMessageEventContent` with the given body and encrypted
|
||||
/// file.
|
||||
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
||||
Self { body, source: MediaSource::Encrypted(Box::new(file)), info: None }
|
||||
Self::new(body, MediaSource::Encrypted(Box::new(file)))
|
||||
}
|
||||
}
|
||||
|
@ -27,16 +27,21 @@ pub struct VideoMessageEventContent {
|
||||
}
|
||||
|
||||
impl VideoMessageEventContent {
|
||||
/// Creates a new `VideoMessageEventContent` with the given body and source.
|
||||
pub fn new(body: String, source: MediaSource) -> Self {
|
||||
Self { body, source, info: None }
|
||||
}
|
||||
|
||||
/// Creates a new non-encrypted `VideoMessageEventContent` with the given body, url and
|
||||
/// optional extra info.
|
||||
pub fn plain(body: String, url: OwnedMxcUri, info: Option<Box<VideoInfo>>) -> Self {
|
||||
Self { body, source: MediaSource::Plain(url), info }
|
||||
pub fn plain(body: String, url: OwnedMxcUri) -> Self {
|
||||
Self::new(body, MediaSource::Plain(url))
|
||||
}
|
||||
|
||||
/// Creates a new encrypted `VideoMessageEventContent` with the given body and encrypted
|
||||
/// file.
|
||||
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
|
||||
Self { body, source: MediaSource::Encrypted(Box::new(file)), info: None }
|
||||
Self::new(body, MediaSource::Encrypted(Box::new(file)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,7 +475,6 @@ fn audio_msgtype_serialization() {
|
||||
RoomMessageEventContent::new(MessageType::Audio(AudioMessageEventContent::plain(
|
||||
"Upload: my_song.mp3".to_owned(),
|
||||
mxc_uri!("mxc://notareal.hs/file").to_owned(),
|
||||
None,
|
||||
)));
|
||||
|
||||
assert_eq!(
|
||||
@ -509,7 +508,6 @@ fn file_msgtype_plain_content_serialization() {
|
||||
RoomMessageEventContent::new(MessageType::File(FileMessageEventContent::plain(
|
||||
"Upload: my_file.txt".to_owned(),
|
||||
mxc_uri!("mxc://notareal.hs/file").to_owned(),
|
||||
None,
|
||||
)));
|
||||
|
||||
assert_eq!(
|
||||
@ -622,7 +620,6 @@ fn image_msgtype_serialization() {
|
||||
RoomMessageEventContent::new(MessageType::Image(ImageMessageEventContent::plain(
|
||||
"Upload: my_image.jpg".to_owned(),
|
||||
mxc_uri!("mxc://notareal.hs/file").to_owned(),
|
||||
None,
|
||||
)));
|
||||
|
||||
assert_eq!(
|
||||
@ -777,7 +774,6 @@ fn video_msgtype_serialization() {
|
||||
RoomMessageEventContent::new(MessageType::Video(VideoMessageEventContent::plain(
|
||||
"Upload: my_video.mp4".to_owned(),
|
||||
mxc_uri!("mxc://notareal.hs/file").to_owned(),
|
||||
None,
|
||||
)));
|
||||
|
||||
assert_eq!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user