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;
</UrlPreviewHolder>
);
};
-
- const renderFile = () => (
- <MFile
- content={getContent()}
- renderFileContent={({ body, mimeType, info, encInfo, url }) => (
- <FileContent
- body={body}
- mimeType={mimeType}
- renderAsPdfFile={() => (
- <ReadPdfFile
- body={body}
- mimeType={mimeType}
- url={url}
- encInfo={encInfo}
- renderViewer={(p) => <PdfViewer {...p} />}
+ const renderCaption = () => {
+ const content: IImageContent = getContent();
+ if(content.filename && content.filename !== content.body) {
+ return (
+ <MText
+ edited={edited}
+ content={content}
+ renderBody={(props) => (
+ <RenderBody
+ {...props}
+ highlightRegex={highlightRegex}
+ htmlReactParserOptions={htmlReactParserOptions}
+ linkifyOpts={linkifyOpts}
/>
)}
- renderAsTextFile={() => (
- <ReadTextFile
+ renderUrlsPreview={urlPreview ? renderUrlsPreview : undefined}
+ />
+ )
+ }
+ return null;
+ }
+
+ const renderFile = () => (
+ <>
+ <MFile
+ content={getContent()}
+ renderFileContent={({ body, mimeType, info, encInfo, url }) => (
+ <FileContent
body={body}
mimeType={mimeType}
- url={url}
- encInfo={encInfo}
- renderViewer={(p) => <TextViewer {...p} />}
- />
- )}
- >
- <DownloadFile body={body} mimeType={mimeType} url={url} encInfo={encInfo} info={info} />
- </FileContent>
- )}
- outlined={outlineAttachment}
- />
+ renderAsPdfFile={() => (
+ <ReadPdfFile
+ body={body}
+ mimeType={mimeType}
+ url={url}
+ encInfo={encInfo}
+ renderViewer={(p) => <PdfViewer {...p} />}
+ />
+ )}
+ renderAsTextFile={() => (
+ <ReadTextFile
+ body={body}
+ mimeType={mimeType}
+ url={url}
+ encInfo={encInfo}
+ renderViewer={(p) => <TextViewer {...p} />}
+ />
+ )}
+ >
+ <DownloadFile body={body} mimeType={mimeType} url={url} encInfo={encInfo} info={info} />
+ </FileContent>
+
+ )}
+ outlined={outlineAttachment}
+ />
+ {renderCaption()}
+ </>
);
if (msgType === MsgType.Text) {
if (msgType === MsgType.Image) {
return (
- <MImage
- content={getContent()}
- renderImageContent={(props) => (
- <ImageContent
- {...props}
- autoPlay={mediaAutoLoad}
- renderImage={(p) => <Image {...p} loading="lazy" />}
- renderViewer={(p) => <ImageViewer {...p} />}
- />
- )}
- outlined={outlineAttachment}
- />
+ <>
+ <MImage
+ content={getContent()}
+ renderImageContent={(props) => (
+ <ImageContent
+ {...props}
+ autoPlay={mediaAutoLoad}
+ renderImage={(p) => <Image {...p} loading="lazy" />}
+ renderViewer={(p) => <ImageViewer {...p} />}
+ />
+ )}
+ outlined={outlineAttachment}
+ />
+ {renderCaption()}
+ </>
);
}
if (msgType === MsgType.Video) {
return (
- <MVideo
- content={getContent()}
- renderAsFile={renderFile}
- renderVideoContent={({ body, info, mimeType, url, encInfo }) => (
- <VideoContent
- body={body}
- info={info}
- mimeType={mimeType}
- url={url}
- encInfo={encInfo}
- renderThumbnail={
- mediaAutoLoad
- ? () => (
+ <>
+ <MVideo
+ content={getContent()}
+ renderAsFile={renderFile}
+ renderVideoContent={({ body, info, mimeType, url, encInfo }) => (
+ <VideoContent
+ body={body}
+ info={info}
+ mimeType={mimeType}
+ url={url}
+ encInfo={encInfo}
+ renderThumbnail={
+ mediaAutoLoad
+ ? () => (
<ThumbnailContent
info={info}
renderImage={(src) => (
)}
/>
)
- : undefined
- }
- renderVideo={(p) => <Video {...p} />}
- />
- )}
- outlined={outlineAttachment}
- />
+ : undefined
+ }
+ renderVideo={(p) => <Video {...p} />}
+ />
+ )}
+ outlined={outlineAttachment}
+ />
+ {renderCaption()}
+ </>
+
);
}
if (msgType === MsgType.Audio) {
return (
- <MAudio
- content={getContent()}
- renderAsFile={renderFile}
- renderAudioContent={(props) => (
- <AudioContent {...props} renderMediaControl={(p) => <MediaControl {...p} />} />
- )}
- outlined={outlineAttachment}
- />
+ <>
+ <MAudio
+ content={getContent()}
+ renderAsFile={renderFile}
+ renderAudioContent={(props) => (
+ <AudioContent {...props} renderMediaControl={(p) => <MediaControl {...p} />} />
+ )}
+ outlined={outlineAttachment}
+ />
+ {renderCaption()}
+ </>
+
);
}
type RenderImageContentProps = {
body: string;
+ filename?: string;
info?: IImageInfo & IThumbnailContent;
mimeType?: string;
url: string;
return (
<Attachment outlined={outlined}>
<AttachmentHeader>
- <FileHeader body={content.body ?? 'Audio'} mimeType={safeMimeType} />
+ <FileHeader body={content.filename ?? content.body ?? 'Audio'} mimeType={safeMimeType} />
</AttachmentHeader>
<AttachmentBox>
<AttachmentContent>
<Attachment outlined={outlined}>
<AttachmentHeader>
<FileHeader
- body={content.body ?? 'Unnamed File'}
+ body={content.filename ?? content.body ?? 'Unnamed File'}
mimeType={fileInfo?.mimetype ?? FALLBACK_MIMETYPE}
/>
</AttachmentHeader>
<AttachmentBox>
<AttachmentContent>
{renderFileContent({
- body: content.body ?? 'File',
+ body: content.filename ?? content.body ?? 'File',
info: fileInfo ?? {},
mimeType: fileInfo?.mimetype ?? FALLBACK_MIMETYPE,
url: mxcUrl,
export const getImageMsgContent = async (
mx: MatrixClient,
item: TUploadItem,
- mxc: string
+ mxc: string,
): Promise<IContent> => {
const { file, originalFile, encInfo } = item;
const [imgError, imgEl] = await to(loadImageElement(getImageFileUrl(originalFile)));
const content: IContent = {
msgtype: MsgType.Image,
+ filename: file.name,
body: file.name,
};
if (imgEl) {
export const getVideoMsgContent = async (
mx: MatrixClient,
item: TUploadItem,
- mxc: string
+ mxc: string,
): Promise<IContent> => {
const { file, originalFile, encInfo } = item;
const content: IContent = {
msgtype: MsgType.Video,
+ filename: file.name,
body: file.name,
};
if (videoEl) {
const { file, encInfo } = item;
const content: IContent = {
msgtype: MsgType.Audio,
+ filename: file.name,
body: file.name,
info: {
mimetype: file.type,