@@ -48,8 +48,8 @@ use ruma::{
48
48
} ,
49
49
receipt:: ReceiptThread ,
50
50
room:: message:: {
51
- ForwardThread , LocationMessageEventContent , MessageType ,
52
- RoomMessageEventContentWithoutRelation ,
51
+ FormattedBody as RumaFormattedBody , ForwardThread , LocationMessageEventContent ,
52
+ MessageType , RoomMessageEventContentWithoutRelation ,
53
53
} ,
54
54
AnyMessageLikeEventContent ,
55
55
} ,
@@ -289,6 +289,7 @@ impl Timeline {
289
289
progress_watcher : Option < Box < dyn ProgressWatcher > > ,
290
290
use_send_queue : bool ,
291
291
) -> Arc < SendAttachmentJoinHandle > {
292
+ let formatted_caption = formatted_caption_from ( & caption, & formatted_caption) ;
292
293
SendAttachmentJoinHandle :: new ( RUNTIME . spawn ( async move {
293
294
let base_image_info = BaseImageInfo :: try_from ( & image_info)
294
295
. map_err ( |_| RoomError :: InvalidAttachmentData ) ?;
@@ -297,7 +298,7 @@ impl Timeline {
297
298
let attachment_config = build_thumbnail_info ( thumbnail_url, image_info. thumbnail_info ) ?
298
299
. info ( attachment_info)
299
300
. caption ( caption)
300
- . formatted_caption ( formatted_caption. map ( Into :: into ) ) ;
301
+ . formatted_caption ( formatted_caption) ;
301
302
302
303
self . send_attachment (
303
304
url,
@@ -321,6 +322,7 @@ impl Timeline {
321
322
progress_watcher : Option < Box < dyn ProgressWatcher > > ,
322
323
use_send_queue : bool ,
323
324
) -> Arc < SendAttachmentJoinHandle > {
325
+ let formatted_caption = formatted_caption_from ( & caption, & formatted_caption) ;
324
326
SendAttachmentJoinHandle :: new ( RUNTIME . spawn ( async move {
325
327
let base_video_info: BaseVideoInfo = BaseVideoInfo :: try_from ( & video_info)
326
328
. map_err ( |_| RoomError :: InvalidAttachmentData ) ?;
@@ -351,6 +353,7 @@ impl Timeline {
351
353
progress_watcher : Option < Box < dyn ProgressWatcher > > ,
352
354
use_send_queue : bool ,
353
355
) -> Arc < SendAttachmentJoinHandle > {
356
+ let formatted_caption = formatted_caption_from ( & caption, & formatted_caption) ;
354
357
SendAttachmentJoinHandle :: new ( RUNTIME . spawn ( async move {
355
358
let base_audio_info: BaseAudioInfo = BaseAudioInfo :: try_from ( & audio_info)
356
359
. map_err ( |_| RoomError :: InvalidAttachmentData ) ?;
@@ -383,6 +386,7 @@ impl Timeline {
383
386
progress_watcher : Option < Box < dyn ProgressWatcher > > ,
384
387
use_send_queue : bool ,
385
388
) -> Arc < SendAttachmentJoinHandle > {
389
+ let formatted_caption = formatted_caption_from ( & caption, & formatted_caption) ;
386
390
SendAttachmentJoinHandle :: new ( RUNTIME . spawn ( async move {
387
391
let base_audio_info: BaseAudioInfo = BaseAudioInfo :: try_from ( & audio_info)
388
392
. map_err ( |_| RoomError :: InvalidAttachmentData ) ?;
@@ -710,6 +714,24 @@ impl Timeline {
710
714
}
711
715
}
712
716
717
+ /// Given a pair of optional `caption` and `formatted_caption` parameters,
718
+ /// return a formatted caption:
719
+ ///
720
+ /// - If a `formatted_caption` exists, return it.
721
+ /// - If it doesn't exist but there is a `caption`, parse it as markdown and
722
+ /// return the result.
723
+ /// - Return `None` if there are no `caption` or `formatted_caption` parameters.
724
+ fn formatted_caption_from (
725
+ caption : & Option < String > ,
726
+ formatted_caption : & Option < FormattedBody > ,
727
+ ) -> Option < RumaFormattedBody > {
728
+ match ( & caption, formatted_caption) {
729
+ ( None , None ) => None ,
730
+ ( Some ( body) , None ) => RumaFormattedBody :: markdown ( body) ,
731
+ ( _, Some ( formatted_body) ) => Some ( formatted_body. clone ( ) . into ( ) ) ,
732
+ }
733
+ }
734
+
713
735
/// A handle to perform actions onto a local echo.
714
736
#[ derive( uniffi:: Object ) ]
715
737
pub struct SendHandle {
0 commit comments