Skip to content

Commit 3662175

Browse files
committed
fix: replies with giphies
1 parent bf51ffc commit 3662175

File tree

6 files changed

+75
-5
lines changed

6 files changed

+75
-5
lines changed

package/src/components/Message/Message.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
489489

490490
const messageContentOrder = messageContentOrderProp.filter((content) => {
491491
if (content === 'quoted_reply') {
492-
return !!message.quoted_message;
492+
return !!message.quoted_message && !hasAttachmentActions;
493493
}
494494

495495
switch (content) {
@@ -700,6 +700,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
700700
goToMessage,
701701
groupStyles,
702702
handleAction,
703+
hasAttachmentActions,
703704
handleReaction,
704705
handleToggleReaction,
705706
hasReactions,

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export type MessageItemViewPropsWithContext = Pick<
200200
| 'alignment'
201201
| 'channel'
202202
| 'groupStyles'
203+
| 'hasAttachmentActions'
203204
| 'isMyMessage'
204205
| 'message'
205206
| 'onlyEmojis'
@@ -241,6 +242,7 @@ const MessageItemViewWithContext = (props: MessageItemViewPropsWithContext) => {
241242
enableMessageGroupingByUser,
242243
enableSwipeToReply,
243244
groupStyles,
245+
hasAttachmentActions,
244246
isMyMessage,
245247
message,
246248
MessageAuthor,
@@ -294,12 +296,13 @@ const MessageItemViewWithContext = (props: MessageItemViewPropsWithContext) => {
294296
});
295297

296298
const groupStyle = `${alignment}_${groupStyles?.[0]?.toLowerCase?.()}`;
299+
const hasVisibleQuotedReply = !!message.quoted_message && !hasAttachmentActions;
297300
const hasStandaloneGiphyOrImgur =
298-
!message.quoted_message &&
301+
!hasVisibleQuotedReply &&
299302
otherAttachments.length > 0 &&
300303
(otherAttachments[0].type === FileTypes.Giphy || otherAttachments[0].type === FileTypes.Imgur);
301304

302-
let noBorder = onlyEmojis && !message.quoted_message;
305+
let noBorder = onlyEmojis && !hasVisibleQuotedReply;
303306
if (otherAttachments.length) {
304307
if (hasStandaloneGiphyOrImgur && !isMyMessage) {
305308
noBorder = false;
@@ -309,7 +312,7 @@ const MessageItemViewWithContext = (props: MessageItemViewPropsWithContext) => {
309312
}
310313

311314
let backgroundColor = semantics.chatBgOutgoing;
312-
if (onlyEmojis && !message.quoted_message) {
315+
if (onlyEmojis && !hasVisibleQuotedReply) {
313316
backgroundColor = 'transparent';
314317
} else if (hasStandaloneGiphyOrImgur) {
315318
backgroundColor = 'transparent';
@@ -522,6 +525,7 @@ export const MessageItemView = (props: MessageItemViewProps) => {
522525
alignment,
523526
channel,
524527
groupStyles,
528+
hasAttachmentActions,
525529
isMyMessage,
526530
message,
527531
contextMenuAnchorRef,
@@ -563,6 +567,7 @@ export const MessageItemView = (props: MessageItemViewProps) => {
563567
enableMessageGroupingByUser,
564568
enableSwipeToReply,
565569
groupStyles,
570+
hasAttachmentActions,
566571
isMyMessage,
567572
message,
568573
MessageAuthor,

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ChannelsStateProvider } from '../../../../contexts/channelsStateContext
88
import { getOrCreateChannelApi } from '../../../../mock-builders/api/getOrCreateChannel';
99
import { useMockedApis } from '../../../../mock-builders/api/useMockedApis';
1010
import {
11+
generateAttachmentAction,
1112
generateGiphyAttachment,
1213
generateVideoAttachment,
1314
} from '../../../../mock-builders/generator/attachment';
@@ -369,6 +370,33 @@ describe('MessageContent', () => {
369370
expect(contentContainerStyle.paddingBottom).toBeGreaterThan(0);
370371
});
371372

373+
it('does not render the quoted reply for an ephemeral giphy preview', async () => {
374+
const user = generateUser();
375+
const message = generateMessage({
376+
attachments: [
377+
{
378+
...generateGiphyAttachment(),
379+
actions: [
380+
generateAttachmentAction(),
381+
generateAttachmentAction(),
382+
generateAttachmentAction(),
383+
],
384+
},
385+
],
386+
quoted_message: generateMessage({ text: 'quoted message', user }),
387+
text: '',
388+
user,
389+
});
390+
391+
renderMessage({ message });
392+
393+
await waitFor(() => {
394+
expect(screen.getByTestId('giphy-action-attachment')).toBeTruthy();
395+
});
396+
397+
expect(screen.queryByText('quoted message')).toBeFalsy();
398+
});
399+
372400
it('renders the FileAttachment component when a file attachment exists', async () => {
373401
const user = generateUser();
374402
const message = generateMessage({

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ 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';
13+
import {
14+
generateAttachmentAction,
15+
generateGiphyAttachment,
16+
} from '../../../../mock-builders/generator/attachment';
1417
import { generateChannelResponse } from '../../../../mock-builders/generator/channel';
1518
import { generateMember } from '../../../../mock-builders/generator/member';
1619
import { generateMessage } from '../../../../mock-builders/generator/message';
@@ -276,4 +279,32 @@ describe('MessageItemView', () => {
276279
expect(wrapperStyle.backgroundColor).not.toBe('transparent');
277280
});
278281
});
282+
283+
it('renders a standalone shell for an ephemeral giphy preview with a quoted reply', async () => {
284+
const user = generateUser();
285+
const message = generateMessage({
286+
attachments: [
287+
{
288+
...generateGiphyAttachment(),
289+
actions: [
290+
generateAttachmentAction(),
291+
generateAttachmentAction(),
292+
generateAttachmentAction(),
293+
],
294+
},
295+
],
296+
quoted_message: generateMessage({ text: 'quoted message', user }),
297+
text: '',
298+
user,
299+
});
300+
301+
renderMessage({ message });
302+
303+
await waitFor(() => {
304+
const wrapperStyle = StyleSheet.flatten(
305+
screen.getByTestId('message-content-wrapper').props.style,
306+
);
307+
expect(wrapperStyle.backgroundColor).toBe('transparent');
308+
});
309+
});
279310
});

package/src/components/Message/hooks/useCreateMessageContext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const useCreateMessageContext = ({
2525
goToMessage,
2626
groupStyles,
2727
handleAction,
28+
hasAttachmentActions,
2829
handleReaction,
2930
handleToggleReaction,
3031
hasReactions,
@@ -79,6 +80,7 @@ export const useCreateMessageContext = ({
7980
goToMessage,
8081
groupStyles: stableGroupStyles,
8182
handleAction,
83+
hasAttachmentActions,
8284
handleReaction,
8385
handleToggleReaction,
8486
hasReactions,
@@ -116,6 +118,7 @@ export const useCreateMessageContext = ({
116118
alignment,
117119
goToMessage,
118120
stableGroupStyles,
121+
hasAttachmentActions,
119122
hasReactions,
120123
messageHasOnlySingleAttachment,
121124
lastGroupMessage,

package/src/contexts/messageContext/MessageContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export type MessageContextValue = {
4040
groupStyles: GroupType[];
4141
/** Handler for actions. Actions in combination with attachments can be used to build [commands](https://getstream.io/chat/docs/#channel_commands). */
4242
handleAction: ActionHandler;
43+
/** Whether or not any message attachment exposes actions. */
44+
hasAttachmentActions: boolean;
4345
handleToggleReaction: (reactionType: string) => Promise<void>;
4446
/** Whether or not message has reactions */
4547
hasReactions: boolean;

0 commit comments

Comments
 (0)