Skip to content

Commit d2aa920

Browse files
fix: forwarding a message twice does not render the attachment (#6960)
* fix: collapsible attachment with text duplicating the content * fix: nested attachment does not render * chore: storybook nested reply * fix: update snapshot test * chore: format code and fix lint issues [skip ci] * code improvements * fix: forward message between channels not rendering image * update snapshot test * fix: collapsible attachment with text duplicating the content * fix: snapshot test --------- Co-authored-by: OtavioStasiak <OtavioStasiak@users.noreply.github.com>
1 parent bfe97f5 commit d2aa920

4 files changed

Lines changed: 8233 additions & 4172 deletions

File tree

app/containers/message/Components/Attachments/Attachments.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ import Audio from './Audio';
77
import Video from './Video';
88
import CollapsibleQuote from './CollapsibleQuote';
99
import AttachedActions from './AttachedActions';
10+
import Reply from './Reply';
1011
import MessageContext from '../../Context';
1112
import { type IMessageAttachments } from '../../interfaces';
1213
import { type IAttachment } from '../../../../definitions';
1314
import { getMessageFromAttachment } from '../../utils';
1415

1516
const removeQuote = (file?: IAttachment) =>
16-
file?.image_url || file?.audio_url || file?.video_url || (file?.actions?.length || 0) > 0 || file?.collapsed;
17+
file?.image_url ||
18+
file?.audio_url ||
19+
file?.video_url ||
20+
file?.collapsed ||
21+
(file?.actions?.length || 0) > 0 ||
22+
(file?.attachments?.length || 0) > 0;
1723

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

77+
if (file.attachments?.length) {
78+
return (
79+
<Reply
80+
key={index}
81+
attachment={file}
82+
timeFormat={timeFormat}
83+
getCustomEmoji={getCustomEmoji}
84+
showAttachment={showAttachment}
85+
msg={msg}
86+
/>
87+
);
88+
}
89+
7190
return null;
7291
});
7392
return <View style={{ gap: 4 }}>{attachmentsElements}</View>;

app/containers/message/Components/Attachments/Quote.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import { getMessageFromAttachment } from '../../utils';
1111
const isQuoteAttachment = (file?: IAttachment): boolean => {
1212
if (!file) return false;
1313

14+
if (file.collapsed) return false;
15+
16+
// Attachments with nested attachments (e.g. message link + quoted image) are rendered only by Attachments as Reply
17+
if (file.attachments?.length) {
18+
return false;
19+
}
20+
1421
if (!file.color && !file.text && (file.image_url || file.audio_url || file.video_url || file.collapsed)) {
1522
return false;
1623
}

app/containers/message/Message.stories.tsx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,53 @@ export const MessageWithReplyLargeFont = () => (
12451245
</>
12461246
);
12471247

1248+
export const MessageWithNestedReplyAndFile = () => (
1249+
<>
1250+
<Message
1251+
msg='Forwarded message with file inside'
1252+
attachments={[
1253+
{
1254+
author_name: 'rocket.cat',
1255+
message_link: 'https://open.rocket.chat/group/msg-id',
1256+
ts: date,
1257+
timeFormat: 'LT',
1258+
text: '',
1259+
attachments: [
1260+
{
1261+
author_name: 'user',
1262+
ts: date,
1263+
timeFormat: 'LT',
1264+
type: 'file',
1265+
title: 'document.pdf',
1266+
title_link: '/file-upload/abc/document.pdf'
1267+
}
1268+
]
1269+
}
1270+
]}
1271+
/>
1272+
<Message
1273+
msg='Forwarded message with nested image'
1274+
attachments={[
1275+
{
1276+
author_name: 'rocket.cat',
1277+
ts: date,
1278+
timeFormat: 'LT',
1279+
text: '',
1280+
attachments: [
1281+
{
1282+
author_name: 'user',
1283+
ts: date,
1284+
timeFormat: 'LT',
1285+
description: 'Nested image from forwarded message',
1286+
image_url: 'https://octodex.github.com/images/yaktocat.png'
1287+
}
1288+
]
1289+
}
1290+
]}
1291+
/>
1292+
</>
1293+
);
1294+
12481295
export const MessageWithReplyAndFileLargeFont = () => (
12491296
<>
12501297
<MessageLargeFont
@@ -2191,6 +2238,20 @@ const collapsedAttachments = {
21912238
}
21922239
]
21932240
};
2241+
2242+
const collapsibleAttachmentWithText = {
2243+
collapsed: true,
2244+
title: 'Collapsed attachment block',
2245+
text: 'This attachment text should NOT appear as plain text above the message or duplicate before the block.',
2246+
description: 'Attachment description that might also leak as duplicate plain text.',
2247+
color: '#2c3e50',
2248+
fields: [
2249+
{ title: 'Field 1', value: 'Value 1', short: true },
2250+
{ title: 'Field 2', value: 'Value 2', short: true },
2251+
{ title: 'Long field', value: 'This field value could also contribute to duplicate text when expanded.', short: false }
2252+
]
2253+
};
2254+
21942255
export const CollapsedAttachments = () => (
21952256
<>
21962257
<Message msg='Message' attachments={[collapsedAttachments]} />
@@ -2207,6 +2268,23 @@ export const CollapsedAttachmentsLargeFont = () => (
22072268
</>
22082269
);
22092270

2271+
export const CollapsibleAttachmentWithText = () => (
2272+
<>
2273+
<Message msg='This is the main message body.' attachments={[collapsibleAttachmentWithText]} />
2274+
<Message msg='This is the main message body.' attachments={[{ ...collapsibleAttachmentWithText, collapsed: false }]} />
2275+
</>
2276+
);
2277+
2278+
export const CollapsibleAttachmentWithTextLargeFont = () => (
2279+
<>
2280+
<MessageLargeFont msg='This is the main message body.' attachments={[collapsibleAttachmentWithText]} />
2281+
<MessageLargeFont
2282+
msg='This is the main message body.'
2283+
attachments={[{ ...collapsibleAttachmentWithText, collapsed: false }]}
2284+
/>
2285+
</>
2286+
);
2287+
22102288
const attachmentWithTextAndLink = [
22112289
{
22122290
title: 'Rocket.Chat',

0 commit comments

Comments
 (0)