Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 20 additions & 1 deletion app/containers/message/Components/Attachments/Attachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import Audio from './Audio';
import Video from './Video';
import CollapsibleQuote from './CollapsibleQuote';
import AttachedActions from './AttachedActions';
import Reply from './Reply';
import MessageContext from '../../Context';
import { type IMessageAttachments } from '../../interfaces';
import { type IAttachment } from '../../../../definitions';
import { getMessageFromAttachment } from '../../utils';

const removeQuote = (file?: IAttachment) =>
file?.image_url || file?.audio_url || file?.video_url || (file?.actions?.length || 0) > 0 || file?.collapsed;
file?.image_url ||
file?.audio_url ||
file?.video_url ||
file?.collapsed ||
(file?.actions?.length || 0) > 0 ||
(file?.attachments?.length || 0) > 0;

const Attachments: React.FC<IMessageAttachments> = React.memo(
({ attachments, timeFormat, showAttachment, getCustomEmoji, author }: IMessageAttachments) => {
Expand Down Expand Up @@ -68,6 +74,19 @@ const Attachments: React.FC<IMessageAttachments> = React.memo(
return <CollapsibleQuote key={index} attachment={file} timeFormat={timeFormat} getCustomEmoji={getCustomEmoji} />;
}

if (file.attachments?.length) {
return (
<Reply
key={index}
attachment={file}
timeFormat={timeFormat}
getCustomEmoji={getCustomEmoji}
showAttachment={showAttachment}
msg={msg}
/>
);
}

return null;
});
return <View style={{ gap: 4 }}>{attachmentsElements}</View>;
Expand Down
7 changes: 7 additions & 0 deletions app/containers/message/Components/Attachments/Quote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import { getMessageFromAttachment } from '../../utils';
const isQuoteAttachment = (file?: IAttachment): boolean => {
if (!file) return false;

if (file.collapsed) return false;

// Attachments with nested attachments (e.g. message link + quoted image) are rendered only by Attachments as Reply
if (file.attachments?.length) {
return false;
}

if (!file.color && !file.text && (file.image_url || file.audio_url || file.video_url || file.collapsed)) {
return false;
}
Expand Down
78 changes: 78 additions & 0 deletions app/containers/message/Message.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,53 @@ export const MessageWithReplyLargeFont = () => (
</>
);

export const MessageWithNestedReplyAndFile = () => (
<>
<Message
msg='Forwarded message with file inside'
attachments={[
{
author_name: 'rocket.cat',
message_link: 'https://open.rocket.chat/group/msg-id',
ts: date,
timeFormat: 'LT',
text: '',
attachments: [
{
author_name: 'user',
ts: date,
timeFormat: 'LT',
type: 'file',
title: 'document.pdf',
title_link: '/file-upload/abc/document.pdf'
}
]
}
]}
/>
<Message
msg='Forwarded message with nested image'
attachments={[
{
author_name: 'rocket.cat',
ts: date,
timeFormat: 'LT',
text: '',
attachments: [
{
author_name: 'user',
ts: date,
timeFormat: 'LT',
description: 'Nested image from forwarded message',
image_url: 'https://octodex.github.com/images/yaktocat.png'
}
]
}
]}
/>
</>
);

export const MessageWithReplyAndFileLargeFont = () => (
<>
<MessageLargeFont
Expand Down Expand Up @@ -2191,6 +2238,20 @@ const collapsedAttachments = {
}
]
};

const collapsibleAttachmentWithText = {
collapsed: true,
title: 'Collapsed attachment block',
text: 'This attachment text should NOT appear as plain text above the message or duplicate before the block.',
description: 'Attachment description that might also leak as duplicate plain text.',
color: '#2c3e50',
fields: [
{ title: 'Field 1', value: 'Value 1', short: true },
{ title: 'Field 2', value: 'Value 2', short: true },
{ title: 'Long field', value: 'This field value could also contribute to duplicate text when expanded.', short: false }
]
};

export const CollapsedAttachments = () => (
<>
<Message msg='Message' attachments={[collapsedAttachments]} />
Expand All @@ -2207,6 +2268,23 @@ export const CollapsedAttachmentsLargeFont = () => (
</>
);

export const CollapsibleAttachmentWithText = () => (
<>
<Message msg='This is the main message body.' attachments={[collapsibleAttachmentWithText]} />
<Message msg='This is the main message body.' attachments={[{ ...collapsibleAttachmentWithText, collapsed: false }]} />
</>
);

export const CollapsibleAttachmentWithTextLargeFont = () => (
<>
<MessageLargeFont msg='This is the main message body.' attachments={[collapsibleAttachmentWithText]} />
<MessageLargeFont
msg='This is the main message body.'
attachments={[{ ...collapsibleAttachmentWithText, collapsed: false }]}
/>
</>
);

const attachmentWithTextAndLink = [
{
title: 'Rocket.Chat',
Expand Down
Loading
Loading