import type { MarkdownFields, MessageAttachmentDefault } from '@rocket.chat/core-typings'; import { isActionAttachment } from '@rocket.chat/core-typings'; import type { ReactNode, ComponentProps } from 'react'; import { ActionAttachment } from './default/ActionAttachtment'; import FieldsAttachment from './default/FieldsAttachment'; import AttachmentAuthor from './structure/AttachmentAuthor'; import AttachmentAuthorAvatar from './structure/AttachmentAuthorAvatar'; import AttachmentAuthorName from './structure/AttachmentAuthorName'; import AttachmentBlock from './structure/AttachmentBlock'; import AttachmentContent from './structure/AttachmentContent'; import AttachmentImage from './structure/AttachmentImage'; import AttachmentRow from './structure/AttachmentRow'; import AttachmentText from './structure/AttachmentText'; import AttachmentThumb from './structure/AttachmentThumb'; import AttachmentTitle from './structure/AttachmentTitle'; import MarkdownText from '../../../MarkdownText'; import { useCollapse } from '../../hooks/useCollapse'; import CollapsibleContent from '../collapsible/CollapsibleContent'; const applyMarkdownIfRequires = ( list: MessageAttachmentDefault['mrkdwn_in'] = ['text', 'pretext'], key: MarkdownFields, text: string, variant: ComponentProps['variant'] = 'inline', ): ReactNode => (list?.includes(key) ? : text); export type DefaultAttachmentProps = MessageAttachmentDefault & { collapseKey?: string; }; const DefaultAttachment = ({ collapseKey, ...attachment }: DefaultAttachmentProps) => { const [collapsed, toggleCollapse] = useCollapse(!!attachment.collapsed, collapseKey); return ( {applyMarkdownIfRequires(attachment.mrkdwn_in, 'pretext', attachment.pretext)} ) } > {attachment.author_name && ( {attachment.author_icon && } {attachment.author_name} )} {attachment.title && ( {attachment.title} {' '} )} {!collapsed && ( <> {attachment.text && ( {applyMarkdownIfRequires(attachment.mrkdwn_in, 'text', attachment.text, 'document')} )} {/* {attachment.fields && ({ ...rest, value: })) : attachment.fields} />} */} {attachment.fields && ( { if (!field.value) { return field; } const { value, title, ...rest } = field; return { ...rest, title: title ? ( `${line} `)} /> ) : null, value: value ? ( `${line} `)} /> ) : null, }; })} /> )} {attachment.image_url && ( )} {/* DEPRECATED */} {isActionAttachment(attachment) && } )} {attachment.thumb_url && } ); }; export default DefaultAttachment;