import React from 'react'; import { MsgType } from 'matrix-js-sdk'; import { HTMLReactParserOptions } from 'html-react-parser'; import { Opts } from 'linkifyjs'; import { AudioContent, DownloadFile, FileContent, ImageContent, MAudio, MBadEncrypted, MEmote, MFile, MImage, MLocation, MNotice, MText, MVideo, ReadPdfFile, ReadTextFile, RenderBody, ThumbnailContent, UnsupportedContent, VideoContent, } from './message'; import { UrlPreviewCard, UrlPreviewHolder } from './url-preview'; import { Image, MediaControl, Video } from './media'; import { ImageViewer } from './image-viewer'; import { PdfViewer } from './Pdf-viewer'; import { TextViewer } from './text-viewer'; import { testMatrixTo } from '../plugins/matrix-to'; import {IImageContent} from "../../types/matrix/common"; type RenderMessageContentProps = { displayName: string; msgType: string; ts: number; edited?: boolean; getContent: () => T; mediaAutoLoad?: boolean; urlPreview?: boolean; highlightRegex?: RegExp; htmlReactParserOptions: HTMLReactParserOptions; linkifyOpts: Opts; outlineAttachment?: boolean; }; export function RenderMessageContent({ displayName, msgType, ts, edited, getContent, mediaAutoLoad, urlPreview, highlightRegex, htmlReactParserOptions, linkifyOpts, outlineAttachment, }: RenderMessageContentProps) { const renderUrlsPreview = (urls: string[]) => { const filteredUrls = urls.filter((url) => !testMatrixTo(url)); if (filteredUrls.length === 0) return undefined; return ( {filteredUrls.map((url) => ( ))} ); }; const renderCaption = () => { const content: IImageContent = getContent(); if(content.filename && content.filename !== content.body) { return ( ( )} renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined} /> ) } return null; } const renderFile = () => ( <> ( ( } /> )} renderAsTextFile={() => ( } /> )} > )} outlined={outlineAttachment} /> {renderCaption()} ); if (msgType === MsgType.Text) { return ( ( )} renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined} /> ); } if (msgType === MsgType.Emote) { return ( ( )} renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined} /> ); } if (msgType === MsgType.Notice) { return ( ( )} renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined} /> ); } if (msgType === MsgType.Image) { return ( <> ( } renderViewer={(p) => } /> )} outlined={outlineAttachment} /> {renderCaption()} ); } if (msgType === MsgType.Video) { return ( <> ( ( ( {body} )} /> ) : undefined } renderVideo={(p) =>