diff --git a/packages/react/src/views/AttachmentHandler/AttachmentMetadata.js b/packages/react/src/views/AttachmentHandler/AttachmentMetadata.js index 0c4eda27a..a3a4076f3 100644 --- a/packages/react/src/views/AttachmentHandler/AttachmentMetadata.js +++ b/packages/react/src/views/AttachmentHandler/AttachmentMetadata.js @@ -41,13 +41,15 @@ const AttachmentMetadata = ({ } else if (attachment?.size) { sizeInBytes = attachment.size; } else { - sizeInBytes = 0; + return null; } const sizeInKB = (sizeInBytes / 1024).toFixed(2); return `${sizeInKB} kB`; }; + const fileSize = getFormattedFileSize(); + return ( - - ({getFormattedFileSize()}) - + {fileSize && ( + + ({fileSize}) + + )} ( - + attachment.attachments.map((nestedAttachment, index) => { + if (nestedAttachment?.audio_url) { + return ( + + ); + } + if (nestedAttachment?.video_url) { + return ( + + ); + } + if (nestedAttachment?.image_url) { + return ( + + ); + } + // Check for wrapped attachments (mirroring Attachment.js logic) + if (nestedAttachment?.attachments?.[0]?.audio_url) { + return ( + + ); + } + if (nestedAttachment?.attachments?.[0]?.video_url) { + return ( + + ); + } + if (nestedAttachment?.attachments?.[0]?.image_url) { + return ( + + ); + } + + return ( - {nestedAttachment?.author_name && ( - <> - - @{nestedAttachment?.author_name} - - )} - - - - - {isExpanded && ( - {nestedAttachment?.text ? ( - nestedAttachment.text[0] === '[' ? ( - nestedAttachment.text.match(/\n(.*)/)?.[1] || '' - ) : ( - + - ) - ) : ( - - + @{nestedAttachment?.author_name} + + )} + + + {!nestedAttachment?.text && !nestedAttachment?.attachments && ( + + )} + + {isExpanded && ( + + {nestedAttachment?.text ? ( + nestedAttachment.text[0] === '[' ? ( + nestedAttachment.text.match(/\n(.*)/)?.[1] || '' + ) : ( + + ) + ) : ( - - {nestedAttachment?.title} - + - {getFileSizeWithFormat( - nestedAttachment?.size, - nestedAttachment?.format - )} + + {nestedAttachment?.title} + + + {getFileSizeWithFormat( + nestedAttachment?.size, + nestedAttachment?.format + )} + - - )} - - )} - - ))} + )} + + )} + + ); + })} );