import React, { useEffect } from 'react'; import ChatMessageAttachmentEntity from '../../../../../Domain/entity/ChatMessageAttachmentEntity'; import { FileType } from '../../../../../Domain/entity/FileTypes'; import VideoBubble from '../VideoBubble/VideoBubble'; import AudioBubble from '../AudioBubble/AudioBubble'; import ImageBubble from '../ImageBubble/ImageBubble'; import FileBubble from '../FileBubble/FileBubble'; import { Creator } from '../../../../../Data/Creator'; interface AttachmentBubbleProps { attachment: ChatMessageAttachmentEntity; typeMessage: 'incoming' | 'outgoing'; } export default function AttachmentBubble({ attachment, typeMessage, }: AttachmentBubbleProps) { const [fileUrl, setFileUrl] = React.useState(''); async function getFileForPreview() { if (attachment.url && attachment.url.length > 0) { let { url } = attachment; const { blobFile } = await Creator.createBlobFromUrl(url); url = blobFile ? URL.createObjectURL(blobFile) : url || ''; setFileUrl(url); } } useEffect(() => { getFileForPreview(); return () => { if (fileUrl) { URL.revokeObjectURL(fileUrl); } }; }, []); if (attachment.type.toString().includes(FileType.video)) { return ; } if (attachment.type.toString().includes(FileType.audio)) { return ( ); } if ( attachment.type.toString().split('/')[1] !== 'heic' && attachment.type.toString().split('/')[1] !== 'heif' && attachment.type.toString().includes(FileType.image) ) { return ; } return ( ); }