Skip to content

Commit

Permalink
Add filename and formatted fields to media messages
Browse files Browse the repository at this point in the history
For MSC2530 media captions
  • Loading branch information
SpiritCroc committed Dec 30, 2023
1 parent b7829d5 commit 89f92b8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
12 changes: 12 additions & 0 deletions crates/ruma-events/src/room/message/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use js_int::UInt;
use ruma_common::OwnedMxcUri;
use serde::{Deserialize, Serialize};

use super::FormattedBody;

use crate::room::{EncryptedFile, MediaSource};

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

/// Formatted form of the message `body`.
#[serde(flatten)]
pub formatted: Option<FormattedBody>,

/// The original filename of the uploaded file.
#[serde(skip_serializing_if = "Option::is_none")]
pub filename: Option<String>,

/// The source of the audio clip.
#[serde(flatten)]
pub source: MediaSource,
Expand Down Expand Up @@ -44,6 +54,8 @@ impl AudioMessageEventContent {
pub fn new(body: String, source: MediaSource) -> Self {
Self {
body,
formatted: None,
filename: None,
source,
info: None,
#[cfg(feature = "unstable-msc3245-v1-compat")]
Expand Down
8 changes: 7 additions & 1 deletion crates/ruma-events/src/room/message/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use js_int::UInt;
use ruma_common::OwnedMxcUri;
use serde::{Deserialize, Serialize};

use super::FormattedBody;

use crate::room::{EncryptedFile, MediaSource, ThumbnailInfo};

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

/// Formatted form of the message `body`.
#[serde(flatten)]
pub formatted: Option<FormattedBody>,

/// The original filename of the uploaded file.
#[serde(skip_serializing_if = "Option::is_none")]
pub filename: Option<String>,
Expand All @@ -30,7 +36,7 @@ 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 }
Self { body, formatted: None, filename: None, source, info: None }
}

/// Creates a new non-encrypted `FileMessageEventContent` with the given body and url.
Expand Down
12 changes: 11 additions & 1 deletion crates/ruma-events/src/room/message/image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use ruma_common::OwnedMxcUri;
use serde::{Deserialize, Serialize};

use super::FormattedBody;

use crate::room::{EncryptedFile, ImageInfo, MediaSource};

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

/// Formatted form of the message `body`.
#[serde(flatten)]
pub formatted: Option<FormattedBody>,

/// The original filename of the uploaded file.
#[serde(skip_serializing_if = "Option::is_none")]
pub filename: Option<String>,

/// The source of the image.
#[serde(flatten)]
pub source: MediaSource,
Expand All @@ -26,7 +36,7 @@ pub struct ImageMessageEventContent {
impl ImageMessageEventContent {
/// Creates a new `ImageMessageEventContent` with the given body and source.
pub fn new(body: String, source: MediaSource) -> Self {
Self { body, source, info: None }
Self { body, formatted: None, filename: None, source, info: None }
}

/// Creates a new non-encrypted `ImageMessageEventContent` with the given body and url.
Expand Down
12 changes: 11 additions & 1 deletion crates/ruma-events/src/room/message/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use js_int::UInt;
use ruma_common::OwnedMxcUri;
use serde::{Deserialize, Serialize};

use super::FormattedBody;

use crate::room::{EncryptedFile, MediaSource, ThumbnailInfo};

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

/// Formatted form of the message `body`.
#[serde(flatten)]
pub formatted: Option<FormattedBody>,

/// The original filename of the uploaded file.
#[serde(skip_serializing_if = "Option::is_none")]
pub filename: Option<String>,

/// The source of the video clip.
#[serde(flatten)]
pub source: MediaSource,
Expand All @@ -27,7 +37,7 @@ 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 }
Self { body, formatted: None, filename: None, source, info: None }
}

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

0 comments on commit 89f92b8

Please sign in to comment.