Skip to content

Commit b5b9a31

Browse files
committed
fix: giphy with reply channel preview
1 parent 027a7c4 commit b5b9a31

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
3+
import { render } from '@testing-library/react-native';
4+
5+
import { generateGiphyAttachment } from '../../../mock-builders/generator/attachment';
6+
import { generateMessage } from '../../../mock-builders/generator/message';
7+
import { generateUser } from '../../../mock-builders/generator/user';
8+
import { getTestClientWithUser } from '../../../mock-builders/mock';
9+
import { Chat } from '../../Chat/Chat';
10+
import { ChannelLastMessagePreview } from '../ChannelLastMessagePreview';
11+
12+
describe('ChannelLastMessagePreview', () => {
13+
it('shows Giphy instead of slash-command text for giphy attachments with quoted replies', async () => {
14+
const client = await getTestClientWithUser({ id: 'preview-user' });
15+
const user = generateUser();
16+
const message = generateMessage({
17+
attachments: [generateGiphyAttachment()],
18+
quoted_message: generateMessage({ text: 'quoted message', user }),
19+
text: '/giphy Cat',
20+
user,
21+
});
22+
23+
const { getByText, queryByText } = render(
24+
<Chat client={client}>
25+
<ChannelLastMessagePreview message={message} />
26+
</Chat>,
27+
);
28+
29+
expect(getByText('Giphy')).toBeTruthy();
30+
expect(queryByText('/giphy Cat')).toBeNull();
31+
});
32+
});

package/src/hooks/messagePreview/useMessagePreviewText.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export const useMessagePreviewText = ({
3535
const onlyAudio = audios?.length === attachmentsLength;
3636
const onlyVoiceRecordings =
3737
voiceRecordings?.length && voiceRecordings?.length === attachmentsLength;
38-
3938
if (message?.type === 'deleted') {
4039
return 'Message deleted';
4140
}
@@ -55,8 +54,12 @@ export const useMessagePreviewText = ({
5554
return 'Location';
5655
}
5756

57+
if (giphys?.length) {
58+
return 'Giphy';
59+
}
60+
5861
if (message?.text) {
59-
return message?.text;
62+
return message.text;
6063
}
6164

6265
if (onlyImages) {
@@ -91,10 +94,6 @@ export const useMessagePreviewText = ({
9194
}
9295
}
9396

94-
if (giphys?.length) {
95-
return 'Giphy';
96-
}
97-
9897
if (onlyFiles && files?.length === 1) {
9998
return files?.[0]?.title;
10099
}

0 commit comments

Comments
 (0)