Skip to content

Commit 8dc8327

Browse files
authored
Merge pull request #639 from GetStream/fix-infite-depth-complexity
Fix Channel infinite depth complexity
2 parents ae50c38 + 47882f5 commit 8dc8327

File tree

5 files changed

+53
-65
lines changed

5 files changed

+53
-65
lines changed

src/components/Channel/Channel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ export type ChannelPropsWithContext<
228228
| 'animatedLongPress'
229229
| 'Attachment'
230230
| 'AttachmentActions'
231-
| 'FileAttachmentIcon'
232231
| 'blockUser'
233232
| 'Card'
234233
| 'CardCover'
@@ -241,6 +240,7 @@ export type ChannelPropsWithContext<
241240
| 'dismissKeyboardOnMessageTouch'
242241
| 'editMessage'
243242
| 'FileAttachment'
243+
| 'FileAttachmentIcon'
244244
| 'FileAttachmentGroup'
245245
| 'flagMessage'
246246
| 'FlatList'
@@ -264,13 +264,12 @@ export type ChannelPropsWithContext<
264264
| 'Message'
265265
| 'messageActions'
266266
| 'MessageAvatar'
267-
| 'MessageDeleted'
268267
| 'MessageContent'
269268
| 'messageContentOrder'
269+
| 'MessageDeleted'
270270
| 'MessageFooter'
271271
| 'MessageHeader'
272272
| 'MessageList'
273-
| 'ScrollToBottomButton'
274273
| 'MessageReplies'
275274
| 'MessageRepliesAvatars'
276275
| 'MessageSimple'
@@ -288,6 +287,7 @@ export type ChannelPropsWithContext<
288287
| 'Reply'
289288
| 'reply'
290289
| 'retry'
290+
| 'ScrollToBottomButton'
291291
| 'selectReaction'
292292
| 'supportedReactions'
293293
| 'threadReply'

src/components/ChannelList/hooks/listeners/useChannelVisible.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useEffect } from 'react';
22
import uniqBy from 'lodash/uniqBy';
33

4-
import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
54
import { getChannel } from '../../utils';
65

6+
import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
7+
78
import type { Channel, Event } from 'stream-chat';
89

910
import type {

src/components/Message/MessageSimple/MessageContent.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ const MessageContentWithContext = <
292292
MessageStatus={MessageStatus}
293293
otherAttachments={otherAttachments}
294294
showMessageStatus={showMessageStatus}
295-
testID='message-header'
296295
/>
297296
)}
298297
<View onLayout={onLayout} style={wrapper}>
@@ -393,7 +392,6 @@ const MessageContentWithContext = <
393392
<MessageFooter
394393
formattedDate={getDateText(formatDate)}
395394
isDeleted={!!message.deleted_at}
396-
testID='message-footer'
397395
/>
398396
</TouchableOpacity>
399397
);

src/components/Message/MessageSimple/MessageDeleted.tsx

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import merge from 'lodash/merge';
55
import { MessageTextContainer } from './MessageTextContainer';
66

77
import {
8+
Alignment,
89
MessageContextValue,
910
useMessageContext,
1011
} from '../../../contexts/messageContext/MessageContext';
@@ -14,6 +15,10 @@ import {
1415
} from '../../../contexts/messagesContext/MessagesContext';
1516
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
1617

18+
import type { MessageFooterProps } from './MessageFooter';
19+
20+
import type { MessageType } from '../../MessageList/hooks/useMessageList';
21+
1722
import type {
1823
DefaultAttachmentType,
1924
DefaultChannelType,
@@ -40,20 +45,6 @@ const styles = StyleSheet.create({
4045
},
4146
});
4247

43-
type MessageDeletedContextProps<
44-
At extends UnknownType = DefaultAttachmentType,
45-
Ch extends UnknownType = DefaultChannelType,
46-
Co extends string = DefaultCommandType,
47-
Ev extends UnknownType = DefaultEventType,
48-
Me extends UnknownType = DefaultMessageType,
49-
Re extends UnknownType = DefaultReactionType,
50-
Us extends UnknownType = DefaultUserType
51-
> = Pick<
52-
MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>,
53-
'alignment' | 'message'
54-
> &
55-
Pick<MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'MessageFooter'>;
56-
5748
type MessageDeletedComponentProps = {
5849
formattedDate: string | Date;
5950
groupStyle: string;
@@ -69,8 +60,12 @@ type MessageDeletedPropsWithContext<
6960
Me extends UnknownType = DefaultMessageType,
7061
Re extends UnknownType = DefaultReactionType,
7162
Us extends UnknownType = DefaultUserType
72-
> = MessageDeletedComponentProps &
73-
MessageDeletedContextProps<At, Ch, Co, Ev, Me, Re, Us>;
63+
> = Pick<
64+
MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>,
65+
'alignment' | 'message'
66+
> &
67+
Pick<MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'MessageFooter'> &
68+
MessageDeletedComponentProps;
7469

7570
const MessageDeletedWithContext = <
7671
At extends UnknownType = DefaultAttachmentType,
@@ -140,11 +135,7 @@ const MessageDeletedWithContext = <
140135
message={{ ...message, text: '_Message deleted_' }}
141136
/>
142137
</View>
143-
<MessageFooter
144-
formattedDate={formattedDate}
145-
isDeleted
146-
testID='message-footer'
147-
/>
138+
<MessageFooter formattedDate={formattedDate} isDeleted />
148139
</View>
149140
);
150141
};
@@ -202,8 +193,13 @@ export type MessageDeletedProps<
202193
Me extends UnknownType = DefaultMessageType,
203194
Re extends UnknownType = DefaultReactionType,
204195
Us extends DefaultUserType = DefaultUserType
205-
> = MessageDeletedComponentProps &
206-
Partial<MessageDeletedContextProps<At, Ch, Co, Ev, Me, Re, Us>>;
196+
> = MessageDeletedComponentProps & {
197+
alignment?: Alignment;
198+
message?: MessageType<At, Ch, Co, Ev, Me, Re, Us>;
199+
MessageFooter?: React.ComponentType<
200+
MessageFooterProps<At, Ch, Co, Ev, Me, Re, Us>
201+
>;
202+
};
207203

208204
export const MessageDeleted = <
209205
At extends UnknownType = DefaultAttachmentType,

src/components/Message/MessageSimple/MessageFooter.tsx

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { Text, View } from 'react-native';
33

44
import {
5+
Alignment,
56
MessageContextValue,
67
useMessageContext,
78
} from '../../../contexts/messageContext/MessageContext';
@@ -14,6 +15,13 @@ import { useTheme } from '../../../contexts/themeContext/ThemeContext';
1415
import { useTranslationContext } from '../../../contexts/translationContext/TranslationContext';
1516
import { Eye } from '../../../icons';
1617

18+
import type { Attachment } from 'stream-chat';
19+
20+
import type { MessageStatusProps } from './MessageStatus';
21+
22+
import type { MessageType } from '../../MessageList/hooks/useMessageList';
23+
24+
import type { ChannelContextValue } from '../../../contexts/channelContext/ChannelContext';
1725
import type {
1826
DefaultAttachmentType,
1927
DefaultChannelType,
@@ -25,7 +33,12 @@ import type {
2533
UnknownType,
2634
} from '../../../types/types';
2735

28-
type MessageFooterContextProps<
36+
type MessageFooterComponentProps = {
37+
formattedDate: string | Date;
38+
isDeleted?: boolean;
39+
};
40+
41+
type MessageFooterPropsWithContext<
2942
At extends UnknownType = DefaultAttachmentType,
3043
Ch extends UnknownType = DefaultChannelType,
3144
Co extends string = DefaultCommandType,
@@ -42,27 +55,8 @@ type MessageFooterContextProps<
4255
| 'showMessageStatus'
4356
| 'lastGroupMessage'
4457
> &
45-
Pick<
46-
MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>,
47-
'MessageStatus' | 'MessageFooter'
48-
>;
49-
50-
type MessageFooterComponentProps = {
51-
formattedDate: string | Date;
52-
testID: string;
53-
isDeleted?: boolean;
54-
};
55-
56-
type MessageFooterPropsWithContext<
57-
At extends UnknownType = DefaultAttachmentType,
58-
Ch extends UnknownType = DefaultChannelType,
59-
Co extends string = DefaultCommandType,
60-
Ev extends UnknownType = DefaultEventType,
61-
Me extends UnknownType = DefaultMessageType,
62-
Re extends UnknownType = DefaultReactionType,
63-
Us extends UnknownType = DefaultUserType
64-
> = MessageFooterComponentProps &
65-
MessageFooterContextProps<At, Ch, Co, Ev, Me, Re, Us>;
58+
Pick<MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'MessageStatus'> &
59+
MessageFooterComponentProps;
6660

6761
const MessageFooterWithContext = <
6862
At extends UnknownType = DefaultAttachmentType,
@@ -85,7 +79,6 @@ const MessageFooterWithContext = <
8579
MessageStatus,
8680
otherAttachments,
8781
showMessageStatus,
88-
testID,
8982
} = props;
9083

9184
const {
@@ -106,7 +99,7 @@ const MessageFooterWithContext = <
10699

107100
if (isDeleted) {
108101
return (
109-
<View style={metaContainer} testID={testID}>
102+
<View style={metaContainer} testID='message-footer'>
110103
<Eye pathFill={isDeleted ? undefined : grey} {...eyeIcon} />
111104
<Text
112105
style={[
@@ -244,8 +237,17 @@ export type MessageFooterProps<
244237
Me extends UnknownType = DefaultMessageType,
245238
Re extends UnknownType = DefaultReactionType,
246239
Us extends DefaultUserType = DefaultUserType
247-
> = MessageFooterComponentProps &
248-
Partial<MessageFooterContextProps<At, Ch, Co, Ev, Me, Re, Us>>;
240+
> = Partial<Pick<ChannelContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'members'>> &
241+
MessageFooterComponentProps & {
242+
alignment?: Alignment;
243+
lastGroupMessage?: boolean;
244+
message?: MessageType<At, Ch, Co, Ev, Me, Re, Us>;
245+
MessageStatus?: React.ComponentType<
246+
MessageStatusProps<At, Ch, Co, Ev, Me, Re, Us>
247+
>;
248+
otherAttachments?: Attachment<At>[];
249+
showMessageStatus?: boolean;
250+
};
249251

250252
export const MessageFooter = <
251253
At extends UnknownType = DefaultAttachmentType,
@@ -267,15 +269,7 @@ export const MessageFooter = <
267269
showMessageStatus,
268270
} = useMessageContext<At, Ch, Co, Ev, Me, Re, Us>();
269271

270-
const { MessageFooter, MessageStatus } = useMessagesContext<
271-
At,
272-
Ch,
273-
Co,
274-
Ev,
275-
Me,
276-
Re,
277-
Us
278-
>();
272+
const { MessageStatus } = useMessagesContext<At, Ch, Co, Ev, Me, Re, Us>();
279273

280274
return (
281275
<MemoizedMessageFooter
@@ -284,7 +278,6 @@ export const MessageFooter = <
284278
lastGroupMessage,
285279
members,
286280
message,
287-
MessageFooter,
288281
MessageStatus,
289282
otherAttachments,
290283
showMessageStatus,

0 commit comments

Comments
 (0)