Skip to content

Commit 381b9cd

Browse files
committed
fix: giphies with replies
1 parent df1adbd commit 381b9cd

4 files changed

Lines changed: 81 additions & 11 deletions

File tree

package/src/components/Message/MessageItemView/MessageContent.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ export const MessageContent = (props: MessageContentProps) => {
617617
const messageHasSingleFile =
618618
messageContentOrder.length === 1 && messageContentOrder[0] === 'files' && isSingleFile;
619619
const messageHasOnlyText = messageContentOrder.length === 1 && messageContentOrder[0] === 'text';
620-
const messageHasGiphyOrImgur =
620+
const messageHasStandaloneGiphyOrImgur =
621+
!message.quoted_message &&
621622
otherAttachments.filter(
622623
(file) => file.type === FileTypes.Giphy || file.type === FileTypes.Imgur,
623624
).length > 0;
@@ -627,17 +628,20 @@ export const MessageContent = (props: MessageContentProps) => {
627628
messageHasSingleMedia ||
628629
messageHasSingleFile ||
629630
messageHasOnlyText ||
630-
messageHasGiphyOrImgur;
631+
messageHasStandaloneGiphyOrImgur;
631632

632633
const hidePaddingHorizontal =
633-
messageHasPoll || messageHasSingleMedia || messageHasSingleFile || messageHasGiphyOrImgur;
634+
messageHasPoll ||
635+
messageHasSingleMedia ||
636+
messageHasSingleFile ||
637+
messageHasStandaloneGiphyOrImgur;
634638

635639
const hidePaddingBottom =
636640
messageHasPoll ||
637641
messageHasSingleMedia ||
638642
messageHasSingleFile ||
639643
messageHasOnlyText ||
640-
messageHasGiphyOrImgur ||
644+
messageHasStandaloneGiphyOrImgur ||
641645
(messageContentOrder.length > 1 &&
642646
messageContentOrder[messageContentOrder.length - 1] === 'text');
643647

package/src/components/Message/MessageItemView/MessageItemView.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { useTheme } from '../../../contexts/themeContext/ThemeContext';
1717
import { useStableCallback } from '../../../hooks/useStableCallback';
1818

1919
import { primitives } from '../../../theme';
20+
import { FileTypes } from '../../../types/types';
2021
import { checkMessageEquality, checkQuotedMessageEquality } from '../../../utils/utils';
2122
import { useMessageData } from '../hooks/useMessageData';
2223

@@ -293,10 +294,14 @@ const MessageItemViewWithContext = (props: MessageItemViewPropsWithContext) => {
293294
});
294295

295296
const groupStyle = `${alignment}_${groupStyles?.[0]?.toLowerCase?.()}`;
297+
const hasStandaloneGiphyOrImgur =
298+
!message.quoted_message &&
299+
otherAttachments.length > 0 &&
300+
(otherAttachments[0].type === FileTypes.Giphy || otherAttachments[0].type === FileTypes.Imgur);
296301

297302
let noBorder = onlyEmojis && !message.quoted_message;
298303
if (otherAttachments.length) {
299-
if (otherAttachments[0].type === 'giphy' && !isMyMessage) {
304+
if (hasStandaloneGiphyOrImgur && !isMyMessage) {
300305
noBorder = false;
301306
} else {
302307
noBorder = true;
@@ -306,10 +311,8 @@ const MessageItemViewWithContext = (props: MessageItemViewPropsWithContext) => {
306311
let backgroundColor = semantics.chatBgOutgoing;
307312
if (onlyEmojis && !message.quoted_message) {
308313
backgroundColor = 'transparent';
309-
} else if (otherAttachments.length) {
310-
if (otherAttachments[0].type === 'giphy') {
311-
backgroundColor = 'transparent';
312-
}
314+
} else if (hasStandaloneGiphyOrImgur) {
315+
backgroundColor = 'transparent';
313316
} else if (isMessageReceivedOrErrorType) {
314317
backgroundColor = semantics.chatBgIncoming;
315318
}

package/src/components/Message/MessageItemView/__tests__/MessageContent.test.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { ChannelsStateProvider } from '../../../../contexts/channelsStateContext
77

88
import { getOrCreateChannelApi } from '../../../../mock-builders/api/getOrCreateChannel';
99
import { useMockedApis } from '../../../../mock-builders/api/useMockedApis';
10-
import { generateVideoAttachment } from '../../../../mock-builders/generator/attachment';
10+
import {
11+
generateGiphyAttachment,
12+
generateVideoAttachment,
13+
} from '../../../../mock-builders/generator/attachment';
1114
import { generateChannelResponse } from '../../../../mock-builders/generator/channel';
1215
import { generateMember } from '../../../../mock-builders/generator/member';
1316
import { generateMessage } from '../../../../mock-builders/generator/message';
@@ -326,6 +329,46 @@ describe('MessageContent', () => {
326329
expect(contentContainerStyle.paddingBottom).toBe(0);
327330
});
328331

332+
it('keeps content padding for a quoted reply with a giphy attachment', async () => {
333+
const user = generateUser();
334+
const message = generateMessage({
335+
attachments: [generateGiphyAttachment()],
336+
quoted_message: generateMessage({ text: 'quoted message', user }),
337+
text: '',
338+
user,
339+
});
340+
341+
renderMessage({ message });
342+
343+
await waitFor(() => {
344+
expect(screen.getByTestId('message-content-wrapper')).toBeTruthy();
345+
expect(screen.getByTestId('giphy-attachment')).toBeTruthy();
346+
});
347+
348+
const giphyAttachment = screen.getByTestId('giphy-attachment');
349+
let ancestor = giphyAttachment.parent;
350+
let contentContainerStyle;
351+
352+
while (ancestor && !contentContainerStyle) {
353+
const flattenedStyle = StyleSheet.flatten(ancestor.props.style);
354+
if (
355+
flattenedStyle &&
356+
'paddingTop' in flattenedStyle &&
357+
'paddingHorizontal' in flattenedStyle &&
358+
'paddingBottom' in flattenedStyle
359+
) {
360+
contentContainerStyle = flattenedStyle;
361+
break;
362+
}
363+
ancestor = ancestor.parent;
364+
}
365+
366+
expect(contentContainerStyle).toBeTruthy();
367+
expect(contentContainerStyle.paddingTop).toBeGreaterThan(0);
368+
expect(contentContainerStyle.paddingHorizontal).toBeGreaterThan(0);
369+
expect(contentContainerStyle.paddingBottom).toBeGreaterThan(0);
370+
});
371+
329372
it('renders the FileAttachment component when a file attachment exists', async () => {
330373
const user = generateUser();
331374
const message = generateMessage({

package/src/components/Message/MessageItemView/__tests__/MessageItemView.test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import { Text } from 'react-native';
3+
import { StyleSheet, Text } from 'react-native';
44
import { GestureDetector } from 'react-native-gesture-handler';
55

66
import { cleanup, render, screen, waitFor } from '@testing-library/react-native';
@@ -10,6 +10,7 @@ import { useMessageContext } from '../../../../contexts/messageContext/MessageCo
1010

1111
import { getOrCreateChannelApi } from '../../../../mock-builders/api/getOrCreateChannel';
1212
import { useMockedApis } from '../../../../mock-builders/api/useMockedApis';
13+
import { generateGiphyAttachment } from '../../../../mock-builders/generator/attachment';
1314
import { generateChannelResponse } from '../../../../mock-builders/generator/channel';
1415
import { generateMember } from '../../../../mock-builders/generator/member';
1516
import { generateMessage } from '../../../../mock-builders/generator/message';
@@ -256,4 +257,23 @@ describe('MessageItemView', () => {
256257
});
257258
});
258259
});
260+
261+
it('keeps the message shell background for a quoted reply with a giphy attachment', async () => {
262+
const user = generateUser();
263+
const message = generateMessage({
264+
attachments: [generateGiphyAttachment()],
265+
quoted_message: generateMessage({ text: 'quoted message', user }),
266+
text: '',
267+
user,
268+
});
269+
270+
renderMessage({ message });
271+
272+
await waitFor(() => {
273+
const wrapperStyle = StyleSheet.flatten(
274+
screen.getByTestId('message-content-wrapper').props.style,
275+
);
276+
expect(wrapperStyle.backgroundColor).not.toBe('transparent');
277+
});
278+
});
259279
});

0 commit comments

Comments
 (0)