import type { IThreadMainMessage, IThreadMessage } from '@rocket.chat/core-typings'; import { isE2EEMessage, isQuoteAttachment } from '@rocket.chat/core-typings'; import { MessageBody } from '@rocket.chat/fuselage'; import type { TranslationKey } from '@rocket.chat/ui-contexts'; import { useUserId, useUserPresence } from '@rocket.chat/ui-contexts'; import type { ReactElement } from 'react'; import { memo } from 'react'; import { useTranslation } from 'react-i18next'; import MessageContentBody from '../../MessageContentBody'; import ReadReceiptIndicator from '../../ReadReceiptIndicator'; import Attachments from '../../content/Attachments'; import BroadcastMetrics from '../../content/BroadcastMetrics'; import Location from '../../content/Location'; import MessageActions from '../../content/MessageActions'; import Reactions from '../../content/Reactions'; import UrlPreviews from '../../content/UrlPreviews'; import { useNormalizedMessage } from '../../hooks/useNormalizedMessage'; import { useOembedLayout } from '../../hooks/useOembedLayout'; import { useSubscriptionFromMessageQuery } from '../../hooks/useSubscriptionFromMessageQuery'; import { useMessageListReadReceipts } from '../../list/MessageListContext'; import UiKitMessageBlock from '../../uikit/UiKitMessageBlock'; type ThreadMessageContentProps = { message: IThreadMessage | IThreadMainMessage; }; const ThreadMessageContent = ({ message }: ThreadMessageContentProps): ReactElement => { const encrypted = isE2EEMessage(message); const { enabled: oembedEnabled } = useOembedLayout(); const subscription = useSubscriptionFromMessageQuery(message).data ?? undefined; const broadcast = subscription?.broadcast ?? false; const uid = useUserId(); const { enabled: readReceiptEnabled } = useMessageListReadReceipts(); const messageUser = { ...message.u, roles: [], ...useUserPresence(message.u._id) }; const { t } = useTranslation(); const normalizedMessage = useNormalizedMessage(message); const isMessageEncrypted = encrypted && normalizedMessage?.e2e === 'pending'; const quotes = normalizedMessage?.attachments?.filter(isQuoteAttachment) || []; const attachments = normalizedMessage?.attachments?.filter((attachment) => !isQuoteAttachment(attachment)) || []; return ( <> {isMessageEncrypted && {t('E2E_message_encrypted_placeholder')}} {!!quotes?.length && } {!normalizedMessage.blocks?.length && !!normalizedMessage.md?.length && ( <> {(!encrypted || normalizedMessage.e2e === 'done') && ( )} )} {normalizedMessage.blocks && ( )} {!!attachments && } {oembedEnabled && !!normalizedMessage.urls?.length && } {normalizedMessage.actionLinks?.length && ( ({ methodId, i18nLabel: i18nLabel as TranslationKey, ...action, }))} /> )} {normalizedMessage.reactions && Object.keys(normalizedMessage.reactions).length && } {normalizedMessage.location && } {broadcast && !!messageUser.username && normalizedMessage.u._id !== uid && ( )} {readReceiptEnabled && } ); }; export default memo(ThreadMessageContent);