Skip to content

Commit 9c15a6f

Browse files
committed
feat: remove StreamChatGenerics and introduce interface merging
1 parent 3acc9c4 commit 9c15a6f

File tree

224 files changed

+2066
-3858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+2066
-3858
lines changed

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"path": "0.12.7",
7878
"react-native-markdown-package": "1.8.2",
7979
"react-native-url-polyfill": "^1.3.0",
80-
"stream-chat": "^8.57.6",
80+
"stream-chat": "9.0.0-rc.4",
8181
"use-sync-external-store": "^1.4.0"
8282
},
8383
"peerDependencies": {

package/src/components/AITypingIndicatorView/AITypingIndicatorView.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@ import { Channel } from 'stream-chat';
77
import { AIStates, useAIState } from './hooks/useAIState';
88

99
import { useChannelContext, useTheme, useTranslationContext } from '../../contexts';
10-
import type { DefaultStreamChatGenerics } from '../../types/types';
1110

12-
export type AITypingIndicatorViewProps<
13-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
14-
> = {
15-
channel?: Channel<StreamChatGenerics>;
11+
export type AITypingIndicatorViewProps = {
12+
channel?: Channel;
1613
};
1714

18-
export const AITypingIndicatorView = <
19-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
20-
>({
15+
export const AITypingIndicatorView = ({
2116
channel: channelFromProps,
22-
}: AITypingIndicatorViewProps<StreamChatGenerics>) => {
17+
}: AITypingIndicatorViewProps) => {
2318
const { t } = useTranslationContext();
24-
const { channel: channelFromContext } = useChannelContext<StreamChatGenerics>();
19+
const { channel: channelFromContext } = useChannelContext();
2520
const channel = channelFromProps || channelFromContext;
2621
const { aiState } = useAIState(channel);
2722
const allowedStates = {

package/src/components/AITypingIndicatorView/hooks/useAIState.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useEffect, useState } from 'react';
33
import { AIState, Channel, Event } from 'stream-chat';
44

55
import { useChatContext } from '../../../contexts';
6-
import type { DefaultStreamChatGenerics } from '../../../types/types';
76

87
export const AIStates = {
98
Error: 'AI_STATE_ERROR',
@@ -18,12 +17,8 @@ export const AIStates = {
1817
* @param {Channel} channel - The channel for which we want to know the AI state.
1918
* @returns {{ aiState: AIState }} The current AI state for the given channel.
2019
*/
21-
export const useAIState = <
22-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
23-
>(
24-
channel?: Channel<StreamChatGenerics>,
25-
): { aiState: AIState } => {
26-
const { isOnline } = useChatContext<StreamChatGenerics>();
20+
export const useAIState = (channel?: Channel): { aiState: AIState } => {
21+
const { isOnline } = useChatContext();
2722

2823
const [aiState, setAiState] = useState<AIState>(AIStates.Idle);
2924

@@ -38,16 +33,13 @@ export const useAIState = <
3833
return;
3934
}
4035

41-
const indicatorChangedListener = channel.on(
42-
'ai_indicator.update',
43-
(event: Event<StreamChatGenerics>) => {
44-
const { cid } = event;
45-
const state = event.ai_state as AIState;
46-
if (channel.cid === cid) {
47-
setAiState(state);
48-
}
49-
},
50-
);
36+
const indicatorChangedListener = channel.on('ai_indicator.update', (event: Event) => {
37+
const { cid } = event;
38+
const state = event.ai_state as AIState;
39+
if (channel.cid === cid) {
40+
setAiState(state);
41+
}
42+
});
5143

5244
const indicatorClearedListener = channel.on('ai_indicator.clear', (event) => {
5345
const { cid } = event;

package/src/components/Attachment/Attachment.tsx

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ import {
1313
} from '../../contexts/messagesContext/MessagesContext';
1414
import { isVideoPlayerAvailable } from '../../native';
1515

16-
import { DefaultStreamChatGenerics, FileTypes } from '../../types/types';
16+
import { FileTypes } from '../../types/types';
1717

1818
export type ActionHandler = (name: string, value: string) => void;
1919

20-
export type AttachmentPropsWithContext<
21-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
22-
> = Pick<
23-
MessagesContextValue<StreamChatGenerics>,
20+
export type AttachmentPropsWithContext = Pick<
21+
MessagesContextValue,
2422
| 'AttachmentActions'
2523
| 'Card'
2624
| 'FileAttachment'
@@ -34,14 +32,10 @@ export type AttachmentPropsWithContext<
3432
/**
3533
* The attachment to render
3634
*/
37-
attachment: AttachmentType<StreamChatGenerics>;
35+
attachment: AttachmentType;
3836
};
3937

40-
const AttachmentWithContext = <
41-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
42-
>(
43-
props: AttachmentPropsWithContext<StreamChatGenerics>,
44-
) => {
38+
const AttachmentWithContext = (props: AttachmentPropsWithContext) => {
4539
const {
4640
attachment,
4741
AttachmentActions,
@@ -68,7 +62,7 @@ const AttachmentWithContext = <
6862
<>
6963
<Gallery images={[attachment]} />
7064
{hasAttachmentActions && (
71-
<AttachmentActions key={`key-actions-${attachment.id}`} {...attachment} />
65+
<AttachmentActions key={`key-actions-${attachment.image_url}`} {...attachment} />
7266
)}
7367
</>
7468
);
@@ -79,7 +73,7 @@ const AttachmentWithContext = <
7973
<>
8074
<Gallery videos={[attachment]} />
8175
{hasAttachmentActions && (
82-
<AttachmentActions key={`key-actions-${attachment.id}`} {...attachment} />
76+
<AttachmentActions key={`key-actions-${attachment.thumb_url}`} {...attachment} />
8377
)}
8478
</>
8579
) : (
@@ -99,18 +93,16 @@ const AttachmentWithContext = <
9993
return (
10094
<>
10195
<Card {...attachment} />
102-
<AttachmentActions key={`key-actions-${attachment.id}`} {...attachment} />
96+
{/** TODO: Please rethink this, the fix is temporary. */}
97+
<AttachmentActions key={`key-actions-${attachment.image_url}`} {...attachment} />
10398
</>
10499
);
105100
} else {
106101
return <Card {...attachment} />;
107102
}
108103
};
109104

110-
const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
111-
prevProps: AttachmentPropsWithContext<StreamChatGenerics>,
112-
nextProps: AttachmentPropsWithContext<StreamChatGenerics>,
113-
) => {
105+
const areEqual = (prevProps: AttachmentPropsWithContext, nextProps: AttachmentPropsWithContext) => {
114106
const {
115107
attachment: prevAttachment,
116108
isAttachmentEqual,
@@ -145,11 +137,9 @@ const MemoizedAttachment = React.memo(
145137
areEqual,
146138
) as typeof AttachmentWithContext;
147139

148-
export type AttachmentProps<
149-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
150-
> = Partial<
140+
export type AttachmentProps = Partial<
151141
Pick<
152-
MessagesContextValue<StreamChatGenerics>,
142+
MessagesContextValue,
153143
| 'AttachmentActions'
154144
| 'Card'
155145
| 'FileAttachment'
@@ -161,16 +151,12 @@ export type AttachmentProps<
161151
| 'isAttachmentEqual'
162152
>
163153
> &
164-
Pick<AttachmentPropsWithContext<StreamChatGenerics>, 'attachment'>;
154+
Pick<AttachmentPropsWithContext, 'attachment'>;
165155

166156
/**
167157
* Attachment - The message attachment
168158
*/
169-
export const Attachment = <
170-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
171-
>(
172-
props: AttachmentProps<StreamChatGenerics>,
173-
) => {
159+
export const Attachment = (props: AttachmentProps) => {
174160
const {
175161
attachment,
176162
AttachmentActions: PropAttachmentActions,
@@ -193,7 +179,7 @@ export const Attachment = <
193179
isAttachmentEqual,
194180
myMessageTheme: ContextMyMessageTheme,
195181
UrlPreview: ContextUrlPreview,
196-
} = useMessagesContext<StreamChatGenerics>();
182+
} = useMessagesContext();
197183

198184
if (!attachment) {
199185
return null;

package/src/components/Attachment/AttachmentActions.tsx

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import {
1717
} from '../../contexts/messageContext/MessageContext';
1818
import { useTheme } from '../../contexts/themeContext/ThemeContext';
1919

20-
import type { DefaultStreamChatGenerics } from '../../types/types';
21-
2220
const styles = StyleSheet.create({
2321
actionButton: {
2422
borderRadius: 20,
@@ -33,22 +31,16 @@ const styles = StyleSheet.create({
3331
},
3432
});
3533

36-
export type AttachmentActionsPropsWithContext<
37-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
38-
> = Pick<Attachment<StreamChatGenerics>, 'actions'> &
39-
Pick<MessageContextValue<StreamChatGenerics>, 'handleAction'> & {
34+
export type AttachmentActionsPropsWithContext = Pick<Attachment, 'actions'> &
35+
Pick<MessageContextValue, 'handleAction'> & {
4036
styles?: Partial<{
4137
actionButton: StyleProp<ViewStyle>;
4238
buttonText: StyleProp<TextStyle>;
4339
container: StyleProp<ViewStyle>;
4440
}>;
4541
};
4642

47-
const AttachmentActionsWithContext = <
48-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
49-
>(
50-
props: AttachmentActionsPropsWithContext<StreamChatGenerics>,
51-
) => {
43+
const AttachmentActionsWithContext = (props: AttachmentActionsPropsWithContext) => {
5244
const { actions, handleAction, styles: stylesProp = {} } = props;
5345

5446
const {
@@ -116,9 +108,9 @@ const AttachmentActionsWithContext = <
116108
);
117109
};
118110

119-
const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
120-
prevProps: AttachmentActionsPropsWithContext<StreamChatGenerics>,
121-
nextProps: AttachmentActionsPropsWithContext<StreamChatGenerics>,
111+
const areEqual = (
112+
prevProps: AttachmentActionsPropsWithContext,
113+
nextProps: AttachmentActionsPropsWithContext,
122114
) => {
123115
const { actions: prevActions } = prevProps;
124116
const { actions: nextActions } = nextProps;
@@ -133,21 +125,15 @@ const MemoizedAttachmentActions = React.memo(
133125
areEqual,
134126
) as typeof AttachmentActionsWithContext;
135127

136-
export type AttachmentActionsProps<
137-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
138-
> = Attachment<StreamChatGenerics> &
139-
Partial<Pick<MessageContextValue<StreamChatGenerics>, 'handleAction'>>;
128+
export type AttachmentActionsProps = Attachment &
129+
Partial<Pick<MessageContextValue, 'handleAction'>>;
140130

141131
/**
142132
* AttachmentActions - The actions you can take on an attachment.
143133
* Actions in combination with attachments can be used to build [commands](https://getstream.io/chat/docs/#channel_commands).
144134
*/
145-
export const AttachmentActions = <
146-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
147-
>(
148-
props: AttachmentActionsProps<StreamChatGenerics>,
149-
) => {
150-
const { handleAction } = useMessageContext<StreamChatGenerics>();
135+
export const AttachmentActions = (props: AttachmentActionsProps) => {
136+
const { handleAction } = useMessageContext();
151137
return <MemoizedAttachmentActions {...{ handleAction }} {...props} />;
152138
};
153139

package/src/components/Attachment/Card.tsx

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
} from '../../contexts/messagesContext/MessagesContext';
2828
import { useTheme } from '../../contexts/themeContext/ThemeContext';
2929
import { Play } from '../../icons/Play';
30-
import { DefaultStreamChatGenerics, FileTypes } from '../../types/types';
30+
import { FileTypes } from '../../types/types';
3131
import { makeImageCompatibleUrl } from '../../utils/utils';
3232
import { ImageBackground } from '../UIComponents/ImageBackground';
3333

@@ -82,16 +82,11 @@ const styles = StyleSheet.create({
8282
},
8383
});
8484

85-
export type CardPropsWithContext<
86-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
87-
> = Attachment<StreamChatGenerics> &
85+
export type CardPropsWithContext = Attachment &
8886
Pick<ChatContextValue, 'ImageComponent'> &
87+
Pick<MessageContextValue, 'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress'> &
8988
Pick<
90-
MessageContextValue<StreamChatGenerics>,
91-
'onLongPress' | 'onPress' | 'onPressIn' | 'preventPress'
92-
> &
93-
Pick<
94-
MessagesContextValue<StreamChatGenerics>,
89+
MessagesContextValue,
9590
'additionalPressableProps' | 'CardCover' | 'CardFooter' | 'CardHeader' | 'myMessageTheme'
9691
> & {
9792
channelId: string | undefined;
@@ -110,11 +105,7 @@ export type CardPropsWithContext<
110105
}>;
111106
};
112107

113-
const CardWithContext = <
114-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
115-
>(
116-
props: CardPropsWithContext<StreamChatGenerics>,
117-
) => {
108+
const CardWithContext = (props: CardPropsWithContext) => {
118109
const {
119110
additionalPressableProps,
120111
author_name,
@@ -289,10 +280,7 @@ const CardWithContext = <
289280
);
290281
};
291282

292-
const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
293-
prevProps: CardPropsWithContext<StreamChatGenerics>,
294-
nextProps: CardPropsWithContext<StreamChatGenerics>,
295-
) => {
283+
const areEqual = (prevProps: CardPropsWithContext, nextProps: CardPropsWithContext) => {
296284
const { myMessageTheme: prevMyMessageTheme } = prevProps;
297285
const { myMessageTheme: nextMyMessageTheme } = nextProps;
298286

@@ -307,34 +295,24 @@ const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = Default
307295

308296
const MemoizedCard = React.memo(CardWithContext, areEqual) as typeof CardWithContext;
309297

310-
export type CardProps<
311-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
312-
> = Attachment<StreamChatGenerics> &
298+
export type CardProps = Attachment &
313299
Partial<
314-
Pick<ChatContextValue<StreamChatGenerics>, 'ImageComponent'> &
315-
Pick<
316-
MessageContextValue<StreamChatGenerics>,
317-
'onLongPress' | 'onPress' | 'onPressIn' | 'myMessageTheme'
318-
> &
300+
Pick<ChatContextValue, 'ImageComponent'> &
301+
Pick<MessageContextValue, 'onLongPress' | 'onPress' | 'onPressIn' | 'myMessageTheme'> &
319302
Pick<
320-
MessagesContextValue<StreamChatGenerics>,
303+
MessagesContextValue,
321304
'additionalPressableProps' | 'CardCover' | 'CardFooter' | 'CardHeader'
322305
>
323306
>;
324307

325308
/**
326309
* UI component for card in attachments.
327310
*/
328-
export const Card = <
329-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
330-
>(
331-
props: CardProps<StreamChatGenerics>,
332-
) => {
333-
const { ImageComponent } = useChatContext<StreamChatGenerics>();
334-
const { message, onLongPress, onPress, onPressIn, preventPress } =
335-
useMessageContext<StreamChatGenerics>();
311+
export const Card = (props: CardProps) => {
312+
const { ImageComponent } = useChatContext();
313+
const { message, onLongPress, onPress, onPressIn, preventPress } = useMessageContext();
336314
const { additionalPressableProps, CardCover, CardFooter, CardHeader, myMessageTheme } =
337-
useMessagesContext<StreamChatGenerics>();
315+
useMessagesContext();
338316

339317
return (
340318
<MemoizedCard

0 commit comments

Comments
 (0)