import type { IMessage } from '@rocket.chat/core-typings'; import { MessageSystem, MessageSystemBody, MessageSystemContainer, MessageSystemLeftContainer, MessageSystemName, MessageSystemTimestamp, MessageSystemBlock, CheckBox, MessageUsername, MessageNameContainer, } from '@rocket.chat/fuselage'; import { useButtonPattern } from '@rocket.chat/fuselage-hooks'; import { MessageTypes } from '@rocket.chat/message-types'; import { UserAvatar } from '@rocket.chat/ui-avatar'; import { useUserDisplayName } from '@rocket.chat/ui-client'; import type { TranslationKey } from '@rocket.chat/ui-contexts'; import { useUserPresence, useUserCard } from '@rocket.chat/ui-contexts'; import type { ComponentProps, ReactElement } from 'react'; import { memo } from 'react'; import { useTranslation } from 'react-i18next'; import { useIsSelecting, useToggleSelect, useIsSelectedMessage, useCountSelected, } from '../../../views/room/MessageList/contexts/SelectedMessagesContext'; import Attachments from '../content/Attachments'; import MessageActions from '../content/MessageActions'; import { useMessageListShowRealName, useMessageListShowUsername, useMessageListFormatDateAndTime, useMessageListFormatTime, } from '../list/MessageListContext'; type SystemMessageProps = { message: IMessage; showUserAvatar: boolean; } & ComponentProps; const SystemMessage = ({ message, showUserAvatar, ...props }: SystemMessageProps): ReactElement => { const { t } = useTranslation(); const formatTime = useMessageListFormatTime(); const formatDateAndTime = useMessageListFormatDateAndTime(); const { triggerProps, openUserCard } = useUserCard(); const showRealName = useMessageListShowRealName(); const user = { ...message.u, roles: [], ...useUserPresence(message.u._id) }; const usernameAndRealNameAreSame = !user.name || user.username === user.name; const showUsername = useMessageListShowUsername() && showRealName && !usernameAndRealNameAreSame; const displayName = useUserDisplayName(user); const messageType = MessageTypes.getType(message); const isSelecting = useIsSelecting(); const toggleSelected = useToggleSelect(message._id); const isSelected = useIsSelectedMessage(message._id); useCountSelected(); const buttonProps = useButtonPattern((e) => openUserCard(e, user.username)); return ( {!isSelecting && showUserAvatar && } {isSelecting && } {displayName} {showUsername && ( <> {' '} @{user.username} )} {messageType && {messageType.text(t, message)}} {formatTime(message.ts)} {message.attachments && ( )} {message.actionLinks?.length && ( ({ methodId, i18nLabel: i18nLabel as TranslationKey, ...action, }))} /> )} ); }; export default memo(SystemMessage);