@@ -48,8 +48,8 @@ use ruma::{
4848 } ,
4949 receipt:: ReceiptThread ,
5050 room:: message:: {
51- ForwardThread , LocationMessageEventContent , MessageType ,
52- RoomMessageEventContentWithoutRelation ,
51+ FormattedBody as RumaFormattedBody , ForwardThread , LocationMessageEventContent ,
52+ MessageType , RoomMessageEventContentWithoutRelation ,
5353 } ,
5454 AnyMessageLikeEventContent ,
5555 } ,
@@ -289,6 +289,7 @@ impl Timeline {
289289 progress_watcher : Option < Box < dyn ProgressWatcher > > ,
290290 use_send_queue : bool ,
291291 ) -> Arc < SendAttachmentJoinHandle > {
292+ let formatted_caption = formatted_caption_from ( & caption, & formatted_caption) ;
292293 SendAttachmentJoinHandle :: new ( RUNTIME . spawn ( async move {
293294 let base_image_info = BaseImageInfo :: try_from ( & image_info)
294295 . map_err ( |_| RoomError :: InvalidAttachmentData ) ?;
@@ -297,7 +298,7 @@ impl Timeline {
297298 let attachment_config = build_thumbnail_info ( thumbnail_url, image_info. thumbnail_info ) ?
298299 . info ( attachment_info)
299300 . caption ( caption)
300- . formatted_caption ( formatted_caption. map ( Into :: into ) ) ;
301+ . formatted_caption ( formatted_caption) ;
301302
302303 self . send_attachment (
303304 url,
@@ -321,6 +322,7 @@ impl Timeline {
321322 progress_watcher : Option < Box < dyn ProgressWatcher > > ,
322323 use_send_queue : bool ,
323324 ) -> Arc < SendAttachmentJoinHandle > {
325+ let formatted_caption = formatted_caption_from ( & caption, & formatted_caption) ;
324326 SendAttachmentJoinHandle :: new ( RUNTIME . spawn ( async move {
325327 let base_video_info: BaseVideoInfo = BaseVideoInfo :: try_from ( & video_info)
326328 . map_err ( |_| RoomError :: InvalidAttachmentData ) ?;
@@ -351,6 +353,7 @@ impl Timeline {
351353 progress_watcher : Option < Box < dyn ProgressWatcher > > ,
352354 use_send_queue : bool ,
353355 ) -> Arc < SendAttachmentJoinHandle > {
356+ let formatted_caption = formatted_caption_from ( & caption, & formatted_caption) ;
354357 SendAttachmentJoinHandle :: new ( RUNTIME . spawn ( async move {
355358 let base_audio_info: BaseAudioInfo = BaseAudioInfo :: try_from ( & audio_info)
356359 . map_err ( |_| RoomError :: InvalidAttachmentData ) ?;
@@ -383,6 +386,7 @@ impl Timeline {
383386 progress_watcher : Option < Box < dyn ProgressWatcher > > ,
384387 use_send_queue : bool ,
385388 ) -> Arc < SendAttachmentJoinHandle > {
389+ let formatted_caption = formatted_caption_from ( & caption, & formatted_caption) ;
386390 SendAttachmentJoinHandle :: new ( RUNTIME . spawn ( async move {
387391 let base_audio_info: BaseAudioInfo = BaseAudioInfo :: try_from ( & audio_info)
388392 . map_err ( |_| RoomError :: InvalidAttachmentData ) ?;
@@ -710,6 +714,24 @@ impl Timeline {
710714 }
711715}
712716
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+
713735/// A handle to perform actions onto a local echo.
714736#[ derive( uniffi:: Object ) ]
715737pub struct SendHandle {
0 commit comments