From d2f255d6134150519ae04d269897b6ce3fcc97a4 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Wed, 20 Nov 2024 15:15:47 +0100 Subject: [PATCH] feat(ffi): add a new function helper to create a caption edit It has the same semantics used when creating a caption (if no formatted caption is provided, assume a provided caption is markdown and use that as the formatted caption). --- bindings/matrix-sdk-ffi/src/timeline/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bindings/matrix-sdk-ffi/src/timeline/mod.rs b/bindings/matrix-sdk-ffi/src/timeline/mod.rs index 740a4f5aef4..af449c112a0 100644 --- a/bindings/matrix-sdk-ffi/src/timeline/mod.rs +++ b/bindings/matrix-sdk-ffi/src/timeline/mod.rs @@ -1308,6 +1308,23 @@ impl TryFrom for SdkEditedContent { } } +/// Create a caption edit. +/// +/// If no `formatted_caption` is provided, then it's assumed the `caption` +/// represents valid Markdown that can be used as the formatted caption. +#[matrix_sdk_ffi_macros::export] +fn create_caption_edit( + caption: Option, + formatted_caption: Option, +) -> EditedContent { + let formatted_caption = + formatted_body_from(caption.as_deref(), formatted_caption.map(Into::into)); + EditedContent::MediaCaption { + caption, + formatted_caption: formatted_caption.as_ref().map(Into::into), + } +} + /// Wrapper to retrieve some timeline item info lazily. #[derive(Clone, uniffi::Object)] pub struct LazyTimelineItemProvider(Arc);