diff --git a/crates/ruma-common/src/events/room/message/audio.rs b/crates/ruma-common/src/events/room/message/audio.rs index 4ec6e85a..7f187304 100644 --- a/crates/ruma-common/src/events/room/message/audio.rs +++ b/crates/ruma-common/src/events/room/message/audio.rs @@ -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>) -> 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))) } } diff --git a/crates/ruma-common/src/events/room/message/file.rs b/crates/ruma-common/src/events/room/message/file.rs index 428ba623..60be19fb 100644 --- a/crates/ruma-common/src/events/room/message/file.rs +++ b/crates/ruma-common/src/events/room/message/file.rs @@ -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>) -> 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))) } } diff --git a/crates/ruma-common/src/events/room/message/image.rs b/crates/ruma-common/src/events/room/message/image.rs index b3fd114c..ef049a14 100644 --- a/crates/ruma-common/src/events/room/message/image.rs +++ b/crates/ruma-common/src/events/room/message/image.rs @@ -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>) -> 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))) } } diff --git a/crates/ruma-common/src/events/room/message/video.rs b/crates/ruma-common/src/events/room/message/video.rs index 21a788b0..32d68fc9 100644 --- a/crates/ruma-common/src/events/room/message/video.rs +++ b/crates/ruma-common/src/events/room/message/video.rs @@ -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>) -> 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))) } } diff --git a/crates/ruma-common/tests/events/room_message.rs b/crates/ruma-common/tests/events/room_message.rs index cfb48fee..8cb28c0a 100644 --- a/crates/ruma-common/tests/events/room_message.rs +++ b/crates/ruma-common/tests/events/room_message.rs @@ -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!(