events: Add builder-style methods to media event content structs

This commit is contained in:
Jonas Platte 2023-06-13 17:05:40 +02:00
parent c1fa8d9406
commit b183677ef5
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
4 changed files with 45 additions and 0 deletions

View File

@ -42,6 +42,15 @@ impl AudioMessageEventContent {
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self::new(body, MediaSource::Encrypted(Box::new(file)))
}
/// Creates a new `AudioMessageEventContent` from `self` with the `info` field set to the given
/// value.
///
/// Since the field is public, you can also assign to it directly. This method merely acts
/// as a shorthand for that, because it is very common to set this field.
pub fn info(self, info: impl Into<Option<Box<AudioInfo>>>) -> Self {
Self { info: info.into(), ..self }
}
}
/// Metadata about an audio clip.

View File

@ -46,6 +46,24 @@ impl FileMessageEventContent {
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self::new(body, MediaSource::Encrypted(Box::new(file)))
}
/// Creates a new `FileMessageEventContent` from `self` with the `filename` field set to the
/// given value.
///
/// Since the field is public, you can also assign to it directly. This method merely acts
/// as a shorthand for that, because it is very common to set this field.
pub fn filename(self, filename: impl Into<Option<String>>) -> Self {
Self { filename: filename.into(), ..self }
}
/// Creates a new `FileMessageEventContent` from `self` with the `info` field set to the given
/// value.
///
/// Since the field is public, you can also assign to it directly. This method merely acts
/// as a shorthand for that, because it is very common to set this field.
pub fn info(self, info: impl Into<Option<Box<FileInfo>>>) -> Self {
Self { info: info.into(), ..self }
}
}
/// Metadata about a file.

View File

@ -41,4 +41,13 @@ impl ImageMessageEventContent {
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self::new(body, MediaSource::Encrypted(Box::new(file)))
}
/// Creates a new `ImageMessageEventContent` from `self` with the `info` field set to the given
/// value.
///
/// Since the field is public, you can also assign to it directly. This method merely acts
/// as a shorthand for that, because it is very common to set this field.
pub fn info(self, info: impl Into<Option<Box<ImageInfo>>>) -> Self {
Self { info: info.into(), ..self }
}
}

View File

@ -43,6 +43,15 @@ impl VideoMessageEventContent {
pub fn encrypted(body: String, file: EncryptedFile) -> Self {
Self::new(body, MediaSource::Encrypted(Box::new(file)))
}
/// Creates a new `VideoMessageEventContent` from `self` with the `info` field set to the given
/// value.
///
/// Since the field is public, you can also assign to it directly. This method merely acts
/// as a shorthand for that, because it is very common to set this field.
pub fn info(self, info: impl Into<Option<Box<VideoInfo>>>) -> Self {
Self { info: info.into(), ..self }
}
}
/// Metadata about a video.