From 9a3cfd019c074f0827672e074bcc37dc60ce3ea3 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 17 Nov 2024 18:25:26 +0000 Subject: [PATCH] Handle sending captions for images --- src/app/features/room/RoomInput.tsx | 7 +++++-- src/app/features/room/msgContent.ts | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index 8fcfbc9720..7a5fce42ff 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -227,9 +227,10 @@ export const RoomInput = forwardRef( const contentsPromises = uploads.map(async (upload) => { const fileItem = selectedFiles.find((f) => f.file === upload.file); if (!fileItem) throw new Error('Broken upload'); + const caption = toPlainText(editor.children).trim() || null; if (fileItem.file.type.startsWith('image')) { - return getImageMsgContent(mx, fileItem, upload.mxc); + return getImageMsgContent(mx, fileItem, upload.mxc, caption); } if (fileItem.file.type.startsWith('video')) { return getVideoMsgContent(mx, fileItem, upload.mxc); @@ -318,7 +319,9 @@ export const RoomInput = forwardRef( content['m.relates_to'].is_falling_back = false; } } - mx.sendMessage(roomId, content); + if (!uploadBoardHandlers.current) { + mx.sendMessage(roomId, content); + } resetEditor(editor); resetEditorHistory(editor); setReplyDraft(undefined); diff --git a/src/app/features/room/msgContent.ts b/src/app/features/room/msgContent.ts index 103e8dcdf9..812a293b38 100644 --- a/src/app/features/room/msgContent.ts +++ b/src/app/features/room/msgContent.ts @@ -42,7 +42,8 @@ const generateThumbnailContent = async ( export const getImageMsgContent = async ( mx: MatrixClient, item: TUploadItem, - mxc: string + mxc: string, + caption?: string ): Promise => { const { file, originalFile, encInfo } = item; const [imgError, imgEl] = await to(loadImageElement(getImageFileUrl(originalFile))); @@ -50,7 +51,8 @@ export const getImageMsgContent = async ( const content: IContent = { msgtype: MsgType.Image, - body: file.name, + filename: file.name, + body: caption || file.name, }; if (imgEl) { const blurHash = encodeBlurHash(imgEl, 512, scaleYDimension(imgEl.width, 512, imgEl.height));