Skip to content

Commit 89f92b8

Browse files
committed
Add filename and formatted fields to media messages
For MSC2530 media captions
1 parent b7829d5 commit 89f92b8

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

crates/ruma-events/src/room/message/audio.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use js_int::UInt;
44
use ruma_common::OwnedMxcUri;
55
use serde::{Deserialize, Serialize};
66

7+
use super::FormattedBody;
8+
79
use crate::room::{EncryptedFile, MediaSource};
810

911
/// The payload for an audio message.
@@ -14,6 +16,14 @@ pub struct AudioMessageEventContent {
1416
/// The textual representation of this message.
1517
pub body: String,
1618

19+
/// Formatted form of the message `body`.
20+
#[serde(flatten)]
21+
pub formatted: Option<FormattedBody>,
22+
23+
/// The original filename of the uploaded file.
24+
#[serde(skip_serializing_if = "Option::is_none")]
25+
pub filename: Option<String>,
26+
1727
/// The source of the audio clip.
1828
#[serde(flatten)]
1929
pub source: MediaSource,
@@ -44,6 +54,8 @@ impl AudioMessageEventContent {
4454
pub fn new(body: String, source: MediaSource) -> Self {
4555
Self {
4656
body,
57+
formatted: None,
58+
filename: None,
4759
source,
4860
info: None,
4961
#[cfg(feature = "unstable-msc3245-v1-compat")]

crates/ruma-events/src/room/message/file.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use js_int::UInt;
22
use ruma_common::OwnedMxcUri;
33
use serde::{Deserialize, Serialize};
44

5+
use super::FormattedBody;
6+
57
use crate::room::{EncryptedFile, MediaSource, ThumbnailInfo};
68

79
/// The payload for a file message.
@@ -14,6 +16,10 @@ pub struct FileMessageEventContent {
1416
/// This is recommended to be the filename of the original upload.
1517
pub body: String,
1618

19+
/// Formatted form of the message `body`.
20+
#[serde(flatten)]
21+
pub formatted: Option<FormattedBody>,
22+
1723
/// The original filename of the uploaded file.
1824
#[serde(skip_serializing_if = "Option::is_none")]
1925
pub filename: Option<String>,
@@ -30,7 +36,7 @@ pub struct FileMessageEventContent {
3036
impl FileMessageEventContent {
3137
/// Creates a new `FileMessageEventContent` with the given body and source.
3238
pub fn new(body: String, source: MediaSource) -> Self {
33-
Self { body, filename: None, source, info: None }
39+
Self { body, formatted: None, filename: None, source, info: None }
3440
}
3541

3642
/// Creates a new non-encrypted `FileMessageEventContent` with the given body and url.

crates/ruma-events/src/room/message/image.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use ruma_common::OwnedMxcUri;
22
use serde::{Deserialize, Serialize};
33

4+
use super::FormattedBody;
5+
46
use crate::room::{EncryptedFile, ImageInfo, MediaSource};
57

68
/// The payload for an image message.
@@ -14,6 +16,14 @@ pub struct ImageMessageEventContent {
1416
/// description for accessibility e.g. "image attachment".
1517
pub body: String,
1618

19+
/// Formatted form of the message `body`.
20+
#[serde(flatten)]
21+
pub formatted: Option<FormattedBody>,
22+
23+
/// The original filename of the uploaded file.
24+
#[serde(skip_serializing_if = "Option::is_none")]
25+
pub filename: Option<String>,
26+
1727
/// The source of the image.
1828
#[serde(flatten)]
1929
pub source: MediaSource,
@@ -26,7 +36,7 @@ pub struct ImageMessageEventContent {
2636
impl ImageMessageEventContent {
2737
/// Creates a new `ImageMessageEventContent` with the given body and source.
2838
pub fn new(body: String, source: MediaSource) -> Self {
29-
Self { body, source, info: None }
39+
Self { body, formatted: None, filename: None, source, info: None }
3040
}
3141

3242
/// Creates a new non-encrypted `ImageMessageEventContent` with the given body and url.

crates/ruma-events/src/room/message/video.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use js_int::UInt;
44
use ruma_common::OwnedMxcUri;
55
use serde::{Deserialize, Serialize};
66

7+
use super::FormattedBody;
8+
79
use crate::room::{EncryptedFile, MediaSource, ThumbnailInfo};
810

911
/// The payload for a video message.
@@ -15,6 +17,14 @@ pub struct VideoMessageEventContent {
1517
/// accessibility, e.g. "video attachment".
1618
pub body: String,
1719

20+
/// Formatted form of the message `body`.
21+
#[serde(flatten)]
22+
pub formatted: Option<FormattedBody>,
23+
24+
/// The original filename of the uploaded file.
25+
#[serde(skip_serializing_if = "Option::is_none")]
26+
pub filename: Option<String>,
27+
1828
/// The source of the video clip.
1929
#[serde(flatten)]
2030
pub source: MediaSource,
@@ -27,7 +37,7 @@ pub struct VideoMessageEventContent {
2737
impl VideoMessageEventContent {
2838
/// Creates a new `VideoMessageEventContent` with the given body and source.
2939
pub fn new(body: String, source: MediaSource) -> Self {
30-
Self { body, source, info: None }
40+
Self { body, formatted: None, filename: None, source, info: None }
3141
}
3242

3343
/// Creates a new non-encrypted `VideoMessageEventContent` with the given body and url.

0 commit comments

Comments
 (0)