import type { IMessage } from '@rocket.chat/core-typings'; import { isDiscussionMessage, isThreadMainMessage, 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 { memo } from 'react'; import { useTranslation } from 'react-i18next'; import { useChat } from '../../../../views/room/contexts/ChatContext'; import MessageContentBody from '../../MessageContentBody'; import ReadReceiptIndicator from '../../ReadReceiptIndicator'; import Attachments from '../../content/Attachments'; import BroadcastMetrics from '../../content/BroadcastMetrics'; import DiscussionMetrics from '../../content/DiscussionMetrics'; import Location from '../../content/Location'; import MessageActions from '../../content/MessageActions'; import Reactions from '../../content/Reactions'; import ThreadMetrics from '../../content/ThreadMetrics'; 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'; export type RoomMessageContentProps = { message: IMessage; unread: boolean; mention: boolean; all: boolean; searchText?: string; }; const RoomMessageContent = ({ message, unread, all, mention, searchText }: RoomMessageContentProps) => { 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 chat = useChat(); 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') && ( )} )} {!!attachments && ( )} {normalizedMessage.blocks && ( )} {oembedEnabled && !!normalizedMessage.urls?.length && } {normalizedMessage.actionLinks?.length && ( ({ methodId, i18nLabel: i18nLabel as TranslationKey, ...action, }))} /> )} {normalizedMessage.reactions && Object.keys(normalizedMessage.reactions).length && } {chat && isThreadMainMessage(normalizedMessage) && ( -1)} mid={normalizedMessage._id} rid={normalizedMessage.rid} lm={normalizedMessage.tlm} unread={unread} mention={mention} all={all} participants={normalizedMessage?.replies} /> )} {isDiscussionMessage(normalizedMessage) && ( )} {normalizedMessage.location && } {broadcast && !!messageUser.username && normalizedMessage.u._id !== uid && ( )} {readReceiptEnabled && } ); }; export default memo(RoomMessageContent);