Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Thread message preview #28454

Merged
merged 18 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/meteor/client/components/GazzodownText.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IRoom } from '@rocket.chat/core-typings';
import type { ChannelMention, UserMention } from '@rocket.chat/gazzodown';
import { Markup, MarkupInteractionContext } from '@rocket.chat/gazzodown';
import { PreviewMarkup, Markup, MarkupInteractionContext } from '@rocket.chat/gazzodown';
import type * as MessageParser from '@rocket.chat/message-parser';
import { escapeRegExp } from '@rocket.chat/string-helpers';
import { RouterContext, useLayout, useUserPreference } from '@rocket.chat/ui-contexts';
Expand All @@ -23,9 +23,10 @@ type GazzodownTextProps = {
}[];
channels?: Pick<IRoom, '_id' | 'name'>[];
searchText?: string;
preview?: boolean;
};

const GazzodownText = ({ tokens, mentions, channels, searchText }: GazzodownTextProps) => {
const GazzodownText = ({ tokens, mentions, channels, searchText, preview }: GazzodownTextProps) => {
const highlights = useMessageListHighlights();
const highlightRegex = useMemo(() => {
if (!highlights?.length) {
Expand Down Expand Up @@ -114,7 +115,7 @@ const GazzodownText = ({ tokens, mentions, channels, searchText }: GazzodownText
onChannelMentionClick,
}}
>
<Markup tokens={tokens} />
{!preview ? <Markup tokens={tokens} /> : <PreviewMarkup tokens={tokens} />}
</MarkupInteractionContext.Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@rocket.chat/fuselage';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React from 'react';
import React, { memo } from 'react';

import { MessageTypes } from '../../../../app/ui-utils/client';
import {
Expand Down Expand Up @@ -120,4 +120,4 @@ const ThreadMessagePreview = ({ message, showUserAvatar, sequential, ...props }:
);
};

export default ThreadMessagePreview;
export default memo(ThreadMessagePreview);
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { isE2EEMessage } from '@rocket.chat/core-typings';
import { PreviewMarkup } from '@rocket.chat/gazzodown';
import { isQuoteAttachment, isE2EEMessage } from '@rocket.chat/core-typings';
import type { Root } from '@rocket.chat/message-parser';
import { useTranslation } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React from 'react';
import React, { memo } from 'react';

import GazzodownText from '../../../GazzodownText';

type ThreadMessagePreviewBodyProps = {
message: IMessage;
Expand All @@ -14,18 +16,20 @@ const ThreadMessagePreviewBody = ({ message }: ThreadMessagePreviewBodyProps): R
const isEncryptedMessage = isE2EEMessage(message);

const getMessage = () => {
const mdTokens: Root | undefined = message.md && [...message.md];
if (message.attachments && isQuoteAttachment(message.attachments[0])) {
mdTokens?.shift();
}
if (!isEncryptedMessage || message.e2e === 'done') {
return message.md ? <PreviewMarkup tokens={message.md} /> : <>{message.msg}</>;
return mdTokens ? <GazzodownText preview tokens={mdTokens} /> : <>{message.msg}</>;
}

if (isEncryptedMessage && message.e2e === 'pending') {
return <>{t('E2E_message_encrypted_placeholder')}</>;
}

return <>{message.msg}</>;
};

return getMessage();
};

export default ThreadMessagePreviewBody;
export default memo(ThreadMessagePreviewBody);