Skip to content

Commit a12a46b

Browse files
pixlwavejmartinesp
authored andcommitted
ffi: Add caption/formatted_caption to media timeline items.
Also includes the computed filename too.
1 parent 93fce02 commit a12a46b

File tree

1 file changed

+64
-12
lines changed

1 file changed

+64
-12
lines changed

bindings/matrix-sdk-ffi/src/ruma.rs

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,31 +277,31 @@ impl TryFrom<MessageType> for RumaMessageType {
277277
RumaImageMessageEventContent::new(content.body, (*content.source).clone())
278278
.info(content.info.map(Into::into).map(Box::new));
279279
event_content.formatted = content.formatted.map(Into::into);
280-
event_content.filename = content.filename;
280+
event_content.filename = content.raw_filename;
281281
Self::Image(event_content)
282282
}
283283
MessageType::Audio { content } => {
284284
let mut event_content =
285285
RumaAudioMessageEventContent::new(content.body, (*content.source).clone())
286286
.info(content.info.map(Into::into).map(Box::new));
287287
event_content.formatted = content.formatted.map(Into::into);
288-
event_content.filename = content.filename;
288+
event_content.filename = content.raw_filename;
289289
Self::Audio(event_content)
290290
}
291291
MessageType::Video { content } => {
292292
let mut event_content =
293293
RumaVideoMessageEventContent::new(content.body, (*content.source).clone())
294294
.info(content.info.map(Into::into).map(Box::new));
295295
event_content.formatted = content.formatted.map(Into::into);
296-
event_content.filename = content.filename;
296+
event_content.filename = content.raw_filename;
297297
Self::Video(event_content)
298298
}
299299
MessageType::File { content } => {
300300
let mut event_content =
301301
RumaFileMessageEventContent::new(content.body, (*content.source).clone())
302302
.info(content.info.map(Into::into).map(Box::new));
303303
event_content.formatted = content.formatted.map(Into::into);
304-
event_content.filename = content.filename;
304+
event_content.filename = content.raw_filename;
305305
Self::File(event_content)
306306
}
307307
MessageType::Notice { content } => {
@@ -337,7 +337,10 @@ impl From<RumaMessageType> for MessageType {
337337
content: ImageMessageContent {
338338
body: c.body.clone(),
339339
formatted: c.formatted.as_ref().map(Into::into),
340-
filename: c.filename.clone(),
340+
raw_filename: c.filename.clone(),
341+
filename: c.filename().to_owned(),
342+
caption: c.caption().map(ToString::to_string),
343+
formatted_caption: c.formatted_caption().map(Into::into),
341344
source: Arc::new(c.source.clone()),
342345
info: c.info.as_deref().map(Into::into),
343346
},
@@ -346,7 +349,10 @@ impl From<RumaMessageType> for MessageType {
346349
content: AudioMessageContent {
347350
body: c.body.clone(),
348351
formatted: c.formatted.as_ref().map(Into::into),
349-
filename: c.filename.clone(),
352+
raw_filename: c.filename.clone(),
353+
filename: c.filename().to_owned(),
354+
caption: c.caption().map(ToString::to_string),
355+
formatted_caption: c.formatted_caption().map(Into::into),
350356
source: Arc::new(c.source.clone()),
351357
info: c.info.as_deref().map(Into::into),
352358
audio: c.audio.map(Into::into),
@@ -357,7 +363,10 @@ impl From<RumaMessageType> for MessageType {
357363
content: VideoMessageContent {
358364
body: c.body.clone(),
359365
formatted: c.formatted.as_ref().map(Into::into),
360-
filename: c.filename.clone(),
366+
raw_filename: c.filename.clone(),
367+
filename: c.filename().to_owned(),
368+
caption: c.caption().map(ToString::to_string),
369+
formatted_caption: c.formatted_caption().map(Into::into),
361370
source: Arc::new(c.source.clone()),
362371
info: c.info.as_deref().map(Into::into),
363372
},
@@ -366,7 +375,10 @@ impl From<RumaMessageType> for MessageType {
366375
content: FileMessageContent {
367376
body: c.body.clone(),
368377
formatted: c.formatted.as_ref().map(Into::into),
369-
filename: c.filename.clone(),
378+
raw_filename: c.filename.clone(),
379+
filename: c.filename().to_owned(),
380+
caption: c.caption().map(ToString::to_string),
381+
formatted_caption: c.formatted_caption().map(Into::into),
370382
source: Arc::new(c.source.clone()),
371383
info: c.info.as_deref().map(Into::into),
372384
},
@@ -440,18 +452,38 @@ pub struct EmoteMessageContent {
440452

441453
#[derive(Clone, uniffi::Record)]
442454
pub struct ImageMessageContent {
455+
/// The original body field, deserialized from the event. Prefer the use of
456+
/// `filename` and `caption` over this.
443457
pub body: String,
458+
/// The original formatted body field, deserialized from the event. Prefer
459+
/// the use of `filename` and `formatted_caption` over this.
444460
pub formatted: Option<FormattedBody>,
445-
pub filename: Option<String>,
461+
/// The original filename field, deserialized from the event. Prefer the use
462+
/// of `filename` over this.
463+
pub raw_filename: Option<String>,
464+
/// The computed filename, for use in a client.
465+
pub filename: String,
466+
pub caption: Option<String>,
467+
pub formatted_caption: Option<FormattedBody>,
446468
pub source: Arc<MediaSource>,
447469
pub info: Option<ImageInfo>,
448470
}
449471

450472
#[derive(Clone, uniffi::Record)]
451473
pub struct AudioMessageContent {
474+
/// The original body field, deserialized from the event. Prefer the use of
475+
/// `filename` and `caption` over this.
452476
pub body: String,
477+
/// The original formatted body field, deserialized from the event. Prefer
478+
/// the use of `filename` and `formatted_caption` over this.
453479
pub formatted: Option<FormattedBody>,
454-
pub filename: Option<String>,
480+
/// The original filename field, deserialized from the event. Prefer the use
481+
/// of `filename` over this.
482+
pub raw_filename: Option<String>,
483+
/// The computed filename, for use in a client.
484+
pub filename: String,
485+
pub caption: Option<String>,
486+
pub formatted_caption: Option<FormattedBody>,
455487
pub source: Arc<MediaSource>,
456488
pub info: Option<AudioInfo>,
457489
pub audio: Option<UnstableAudioDetailsContent>,
@@ -460,18 +492,38 @@ pub struct AudioMessageContent {
460492

461493
#[derive(Clone, uniffi::Record)]
462494
pub struct VideoMessageContent {
495+
/// The original body field, deserialized from the event. Prefer the use of
496+
/// `filename` and `caption` over this.
463497
pub body: String,
498+
/// The original formatted body field, deserialized from the event. Prefer
499+
/// the use of `filename` and `formatted_caption` over this.
464500
pub formatted: Option<FormattedBody>,
465-
pub filename: Option<String>,
501+
/// The original filename field, deserialized from the event. Prefer the use
502+
/// of `filename` over this.
503+
pub raw_filename: Option<String>,
504+
/// The computed filename, for use in a client.
505+
pub filename: String,
506+
pub caption: Option<String>,
507+
pub formatted_caption: Option<FormattedBody>,
466508
pub source: Arc<MediaSource>,
467509
pub info: Option<VideoInfo>,
468510
}
469511

470512
#[derive(Clone, uniffi::Record)]
471513
pub struct FileMessageContent {
514+
/// The original body field, deserialized from the event. Prefer the use of
515+
/// `filename` and `caption` over this.
472516
pub body: String,
517+
/// The original formatted body field, deserialized from the event. Prefer
518+
/// the use of `filename` and `formatted_caption` over this.
473519
pub formatted: Option<FormattedBody>,
474-
pub filename: Option<String>,
520+
/// The original filename field, deserialized from the event. Prefer the use
521+
/// of `filename` over this.
522+
pub raw_filename: Option<String>,
523+
/// The computed filename, for use in a client.
524+
pub filename: String,
525+
pub caption: Option<String>,
526+
pub formatted_caption: Option<FormattedBody>,
475527
pub source: Arc<MediaSource>,
476528
pub info: Option<FileInfo>,
477529
}

0 commit comments

Comments
 (0)