Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 2s
132 lines
4.5 KiB
TypeScript
132 lines
4.5 KiB
TypeScript
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, KeyboardEvent } from 'react';
|
|
import { memo } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { normalizeUsername } from '../../../../lib/utils/normalizeUsername';
|
|
import {
|
|
useIsSelecting,
|
|
useToggleSelect,
|
|
useIsSelectedMessage,
|
|
useCountSelected,
|
|
} from '../../../views/room/MessageList/contexts/SelectedMessagesContext';
|
|
import Attachments from '../content/Attachments';
|
|
import MessageActions from '../content/MessageActions';
|
|
import { getCheckboxLabel } from '../helpers/getCheckboxLabel';
|
|
import {
|
|
useMessageListShowRealName,
|
|
useMessageListShowUsername,
|
|
useMessageListFormatDateAndTime,
|
|
useMessageListFormatTime,
|
|
} from '../list/MessageListContext';
|
|
|
|
export type SystemMessageProps = {
|
|
message: IMessage;
|
|
showUserAvatar: boolean;
|
|
} & ComponentProps<typeof MessageSystem>;
|
|
|
|
const SystemMessage = ({ message, showUserAvatar, ...props }: SystemMessageProps) => {
|
|
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 normalizedUsername = normalizeUsername(user.username);
|
|
const usernameAndRealNameAreSame = !user.name || normalizedUsername === 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));
|
|
|
|
const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
if (!isSelecting) return;
|
|
|
|
if (!(e.code === 'Space' || e.code === 'Enter')) return;
|
|
|
|
e.preventDefault();
|
|
toggleSelected();
|
|
};
|
|
|
|
const checkboxLabel = getCheckboxLabel(message, t);
|
|
|
|
return (
|
|
<MessageSystem
|
|
role='listitem'
|
|
aria-roledescription={t('system_message')}
|
|
tabIndex={0}
|
|
onClick={isSelecting ? toggleSelected : undefined}
|
|
onKeyDown={handleKeyDown}
|
|
isSelected={isSelected}
|
|
data-system-message-type={message.t}
|
|
{...props}
|
|
>
|
|
<MessageSystemLeftContainer>
|
|
{!isSelecting && showUserAvatar && <UserAvatar username={message.u.username} size='x18' />}
|
|
{isSelecting && <CheckBox checked={isSelected} onChange={toggleSelected} aria-label={checkboxLabel} />}
|
|
</MessageSystemLeftContainer>
|
|
<MessageSystemContainer>
|
|
<MessageSystemBlock>
|
|
<MessageNameContainer style={{ cursor: 'pointer' }} {...buttonProps} {...triggerProps}>
|
|
<MessageSystemName>{displayName}</MessageSystemName>
|
|
{showUsername && (
|
|
<>
|
|
{' '}
|
|
<MessageUsername data-username={normalizedUsername}>@{normalizedUsername}</MessageUsername>
|
|
</>
|
|
)}
|
|
</MessageNameContainer>
|
|
{messageType && (
|
|
<MessageSystemBody role='document' aria-roledescription={t('system_message_body')}>
|
|
{messageType.text(t, message)}
|
|
</MessageSystemBody>
|
|
)}
|
|
<MessageSystemTimestamp title={formatDateAndTime(message.ts)}>{formatTime(message.ts)}</MessageSystemTimestamp>
|
|
</MessageSystemBlock>
|
|
{message.attachments && (
|
|
<MessageSystemBlock>
|
|
<Attachments attachments={message.attachments} />
|
|
</MessageSystemBlock>
|
|
)}
|
|
{message.actionLinks?.length && (
|
|
<MessageActions
|
|
message={message}
|
|
actions={message.actionLinks.map(({ method_id: methodId, i18nLabel, ...action }) => ({
|
|
methodId,
|
|
i18nLabel: i18nLabel as TranslationKey,
|
|
...action,
|
|
}))}
|
|
/>
|
|
)}
|
|
</MessageSystemContainer>
|
|
</MessageSystem>
|
|
);
|
|
};
|
|
|
|
export default memo(SystemMessage);
|