-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Expand file tree
/
Copy pathThreadMessageContent.tsx
More file actions
99 lines (79 loc) · 4.09 KB
/
ThreadMessageContent.tsx
File metadata and controls
99 lines (79 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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 { useMaxMarkdownParseLength } from '../../hooks/useMaxMarkdownParseLength';
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 maxMarkdownParseLength = useMaxMarkdownParseLength();
const { t } = useTranslation();
const normalizedMessage = useNormalizedMessage(message, maxMarkdownParseLength);
const isMessageEncrypted = encrypted && normalizedMessage?.e2e === 'pending';
const quotes = normalizedMessage?.attachments?.filter(isQuoteAttachment) || [];
const attachments = normalizedMessage?.attachments?.filter((attachment) => !isQuoteAttachment(attachment)) || [];
return (
<>
{isMessageEncrypted && (
<MessageBody role='document' aria-roledescription={t('message_body')}>
{t('E2E_message_encrypted_placeholder')}
</MessageBody>
)}
{!!quotes?.length && <Attachments attachments={quotes} />}
{!normalizedMessage.blocks?.length && !!normalizedMessage.md?.length && (
<>
{(!encrypted || normalizedMessage.e2e === 'done') && (
<MessageContentBody md={normalizedMessage.md} mentions={normalizedMessage.mentions} channels={normalizedMessage.channels} />
)}
</>
)}
{normalizedMessage.blocks && (
<UiKitMessageBlock rid={normalizedMessage.rid} mid={normalizedMessage._id} blocks={normalizedMessage.blocks} />
)}
{!!attachments && <Attachments id={message.files?.[0]?._id} attachments={attachments} />}
{oembedEnabled && !!normalizedMessage.urls?.length && <UrlPreviews urls={normalizedMessage.urls} />}
{normalizedMessage.actionLinks?.length && (
<MessageActions
message={normalizedMessage}
actions={normalizedMessage.actionLinks.map(({ method_id: methodId, i18nLabel, ...action }) => ({
methodId,
i18nLabel: i18nLabel as TranslationKey,
...action,
}))}
/>
)}
{normalizedMessage.reactions && Object.keys(normalizedMessage.reactions).length && <Reactions message={normalizedMessage} />}
{normalizedMessage.location && <Location location={normalizedMessage.location} />}
{broadcast && !!messageUser.username && normalizedMessage.u._id !== uid && (
<BroadcastMetrics username={messageUser.username} message={normalizedMessage} />
)}
{readReceiptEnabled && <ReadReceiptIndicator mid={normalizedMessage._id} unread={normalizedMessage.unread} />}
</>
);
};
export default memo(ThreadMessageContent);