Skip to content

Commit 3b45809

Browse files
committed
refactor: generics to single generic
1 parent 4668b2a commit 3b45809

File tree

144 files changed

+2408
-5761
lines changed

Some content is hidden

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

144 files changed

+2408
-5761
lines changed

examples/ExpoMessaging/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6203,10 +6203,10 @@ [email protected]:
62036203
version "0.0.0"
62046204
uid ""
62056205

6206-
stream-chat@^5.1.2:
6207-
version "5.1.2"
6208-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.1.2.tgz#c55d3078505d957a6b0db18e3af25ebbec7b8746"
6209-
integrity sha512-Hqxj6iJdV10YG2hZXRhkVtVm6lEUuRK+AuTmtw639CTo3RokQiBTZ7+hYCqayhIFAX2Lrt6Drfqiol8lmcreag==
6206+
stream-chat@5.4.0:
6207+
version "5.4.0"
6208+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.4.0.tgz#edbfbda56a3b1e3655e61050c71fd4042238575e"
6209+
integrity sha512-Av32wLIp+waBcqNJfAZaqdS9CUXN+7oU3A7TOF54A0t6V9iUDM7XHuztOUa5itcv2lz3+ZkkIa9fuoDEcmEe0A==
62106210
dependencies:
62116211
"@babel/runtime" "^7.16.3"
62126212
"@types/jsonwebtoken" "^8.5.6"

examples/NativeMessaging/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6985,10 +6985,10 @@ [email protected]:
69856985
version "0.0.0"
69866986
uid ""
69876987

6988-
stream-chat@^5.1.2:
6989-
version "5.1.2"
6990-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.1.2.tgz#c55d3078505d957a6b0db18e3af25ebbec7b8746"
6991-
integrity sha512-Hqxj6iJdV10YG2hZXRhkVtVm6lEUuRK+AuTmtw639CTo3RokQiBTZ7+hYCqayhIFAX2Lrt6Drfqiol8lmcreag==
6988+
stream-chat@5.4.0:
6989+
version "5.4.0"
6990+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.4.0.tgz#edbfbda56a3b1e3655e61050c71fd4042238575e"
6991+
integrity sha512-Av32wLIp+waBcqNJfAZaqdS9CUXN+7oU3A7TOF54A0t6V9iUDM7XHuztOUa5itcv2lz3+ZkkIa9fuoDEcmEe0A==
69926992
dependencies:
69936993
"@babel/runtime" "^7.16.3"
69946994
"@types/jsonwebtoken" "^8.5.6"

examples/SampleApp/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7375,10 +7375,10 @@ [email protected]:
73757375
version "0.0.0"
73767376
uid ""
73777377

7378-
stream-chat@^5.1.2:
7379-
version "5.1.2"
7380-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.1.2.tgz#c55d3078505d957a6b0db18e3af25ebbec7b8746"
7381-
integrity sha512-Hqxj6iJdV10YG2hZXRhkVtVm6lEUuRK+AuTmtw639CTo3RokQiBTZ7+hYCqayhIFAX2Lrt6Drfqiol8lmcreag==
7378+
stream-chat@5.4.0:
7379+
version "5.4.0"
7380+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.4.0.tgz#edbfbda56a3b1e3655e61050c71fd4042238575e"
7381+
integrity sha512-Av32wLIp+waBcqNJfAZaqdS9CUXN+7oU3A7TOF54A0t6V9iUDM7XHuztOUa5itcv2lz3+ZkkIa9fuoDEcmEe0A==
73827382
dependencies:
73837383
"@babel/runtime" "^7.16.3"
73847384
"@types/jsonwebtoken" "^8.5.6"

examples/TypeScriptMessaging/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7108,10 +7108,10 @@ [email protected]:
71087108
version "0.0.0"
71097109
uid ""
71107110

7111-
stream-chat@^5.1.2:
7112-
version "5.1.2"
7113-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.1.2.tgz#c55d3078505d957a6b0db18e3af25ebbec7b8746"
7114-
integrity sha512-Hqxj6iJdV10YG2hZXRhkVtVm6lEUuRK+AuTmtw639CTo3RokQiBTZ7+hYCqayhIFAX2Lrt6Drfqiol8lmcreag==
7111+
stream-chat@5.4.0:
7112+
version "5.4.0"
7113+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-5.4.0.tgz#edbfbda56a3b1e3655e61050c71fd4042238575e"
7114+
integrity sha512-Av32wLIp+waBcqNJfAZaqdS9CUXN+7oU3A7TOF54A0t6V9iUDM7XHuztOUa5itcv2lz3+ZkkIa9fuoDEcmEe0A==
71157115
dependencies:
71167116
"@babel/runtime" "^7.16.3"
71177117
"@types/jsonwebtoken" "^8.5.6"

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"path": "0.12.7",
8181
"react-art": "^17.0.2",
8282
"react-native-markdown-package": "1.8.1",
83-
"stream-chat": "^5.1.2"
83+
"stream-chat": "5.4.0"
8484
},
8585
"peerDependencies": {
8686
"react-native-svg": "^12.1.0"

package/src/components/Attachment/Attachment.tsx

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

3-
import type { Attachment as AttachmentType } from 'stream-chat';
3+
import type { Attachment as AttachmentType, ExtendableGenerics } from 'stream-chat';
44

55
import { AttachmentActions as AttachmentActionsDefault } from '../../components/Attachment/AttachmentActions';
66
import { Card as CardDefault } from '../../components/Attachment/Card';
@@ -12,47 +12,26 @@ import {
1212
useMessagesContext,
1313
} from '../../contexts/messagesContext/MessagesContext';
1414

15-
import type {
16-
DefaultAttachmentType,
17-
DefaultChannelType,
18-
DefaultCommandType,
19-
DefaultEventType,
20-
DefaultMessageType,
21-
DefaultReactionType,
22-
DefaultUserType,
23-
UnknownType,
24-
} from '../../types/types';
15+
import type { DefaultStreamChatGenerics } from '../../types/types';
2516

2617
export type ActionHandler = (name: string, value: string) => void;
2718

2819
export type AttachmentPropsWithContext<
29-
At extends UnknownType = DefaultAttachmentType,
30-
Ch extends UnknownType = DefaultChannelType,
31-
Co extends string = DefaultCommandType,
32-
Ev extends UnknownType = DefaultEventType,
33-
Me extends UnknownType = DefaultMessageType,
34-
Re extends UnknownType = DefaultReactionType,
35-
Us extends UnknownType = DefaultUserType,
20+
StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics,
3621
> = Pick<
37-
MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>,
22+
MessagesContextValue<StreamChatClient>,
3823
'AttachmentActions' | 'Card' | 'FileAttachment' | 'Gallery' | 'Giphy' | 'UrlPreview'
3924
> & {
4025
/**
4126
* The attachment to render
4227
*/
43-
attachment: AttachmentType<At>;
28+
attachment: AttachmentType<StreamChatClient>;
4429
};
4530

4631
const AttachmentWithContext = <
47-
At extends UnknownType = DefaultAttachmentType,
48-
Ch extends UnknownType = DefaultChannelType,
49-
Co extends string = DefaultCommandType,
50-
Ev extends UnknownType = DefaultEventType,
51-
Me extends UnknownType = DefaultMessageType,
52-
Re extends UnknownType = DefaultReactionType,
53-
Us extends UnknownType = DefaultUserType,
32+
StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics,
5433
>(
55-
props: AttachmentPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>,
34+
props: AttachmentPropsWithContext<StreamChatClient>,
5635
) => {
5736
const { attachment, AttachmentActions, Card, FileAttachment, Gallery, Giphy, UrlPreview } = props;
5837

@@ -103,17 +82,9 @@ const AttachmentWithContext = <
10382
}
10483
};
10584

106-
const areEqual = <
107-
At extends UnknownType = DefaultAttachmentType,
108-
Ch extends UnknownType = DefaultChannelType,
109-
Co extends string = DefaultCommandType,
110-
Ev extends UnknownType = DefaultEventType,
111-
Me extends UnknownType = DefaultMessageType,
112-
Re extends UnknownType = DefaultReactionType,
113-
Us extends UnknownType = DefaultUserType,
114-
>(
115-
prevProps: AttachmentPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>,
116-
nextProps: AttachmentPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>,
85+
const areEqual = <StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics>(
86+
prevProps: AttachmentPropsWithContext<StreamChatClient>,
87+
nextProps: AttachmentPropsWithContext<StreamChatClient>,
11788
) => {
11889
const { attachment: prevAttachment } = prevProps;
11990
const { attachment: nextAttachment } = nextProps;
@@ -132,34 +103,20 @@ const MemoizedAttachment = React.memo(
132103
) as typeof AttachmentWithContext;
133104

134105
export type AttachmentProps<
135-
At extends UnknownType = DefaultAttachmentType,
136-
Ch extends UnknownType = DefaultChannelType,
137-
Co extends string = DefaultCommandType,
138-
Ev extends UnknownType = DefaultEventType,
139-
Me extends UnknownType = DefaultMessageType,
140-
Re extends UnknownType = DefaultReactionType,
141-
Us extends UnknownType = DefaultUserType,
106+
StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics,
142107
> = Partial<
143108
Pick<
144-
MessagesContextValue<At, Ch, Co, Ev, Me, Re, Us>,
109+
MessagesContextValue<StreamChatClient>,
145110
'AttachmentActions' | 'Card' | 'FileAttachment' | 'Gallery' | 'Giphy' | 'UrlPreview'
146111
>
147112
> &
148-
Pick<AttachmentPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>, 'attachment'>;
113+
Pick<AttachmentPropsWithContext<StreamChatClient>, 'attachment'>;
149114

150115
/**
151116
* Attachment - The message attachment
152117
*/
153-
export const Attachment = <
154-
At extends UnknownType = DefaultAttachmentType,
155-
Ch extends UnknownType = DefaultChannelType,
156-
Co extends string = DefaultCommandType,
157-
Ev extends UnknownType = DefaultEventType,
158-
Me extends UnknownType = DefaultMessageType,
159-
Re extends UnknownType = DefaultReactionType,
160-
Us extends UnknownType = DefaultUserType,
161-
>(
162-
props: AttachmentProps<At, Ch, Co, Ev, Me, Re, Us>,
118+
export const Attachment = <StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics>(
119+
props: AttachmentProps<StreamChatClient>,
163120
) => {
164121
const {
165122
attachment,
@@ -178,7 +135,7 @@ export const Attachment = <
178135
Gallery: ContextGallery,
179136
Giphy: ContextGiphy,
180137
UrlPreview: ContextUrlPreview,
181-
} = useMessagesContext<At, Ch, Co, Ev, Me, Re, Us>();
138+
} = useMessagesContext<StreamChatClient>();
182139

183140
if (!attachment) {
184141
return null;

package/src/components/Attachment/AttachmentActions.tsx

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,15 @@ import {
99
ViewStyle,
1010
} from 'react-native';
1111

12-
import type { Attachment } from 'stream-chat';
12+
import type { Attachment, ExtendableGenerics } from 'stream-chat';
1313

1414
import {
1515
MessageContextValue,
1616
useMessageContext,
1717
} from '../../contexts/messageContext/MessageContext';
1818
import { useTheme } from '../../contexts/themeContext/ThemeContext';
1919

20-
import type {
21-
DefaultAttachmentType,
22-
DefaultChannelType,
23-
DefaultCommandType,
24-
DefaultEventType,
25-
DefaultMessageType,
26-
DefaultReactionType,
27-
DefaultUserType,
28-
UnknownType,
29-
} from '../../types/types';
20+
import type { DefaultStreamChatGenerics } from '../../types/types';
3021

3122
const styles = StyleSheet.create({
3223
actionButton: {
@@ -43,15 +34,9 @@ const styles = StyleSheet.create({
4334
});
4435

4536
export type AttachmentActionsPropsWithContext<
46-
At extends UnknownType = DefaultAttachmentType,
47-
Ch extends UnknownType = DefaultChannelType,
48-
Co extends string = DefaultCommandType,
49-
Ev extends UnknownType = DefaultEventType,
50-
Me extends UnknownType = DefaultMessageType,
51-
Re extends UnknownType = DefaultReactionType,
52-
Us extends UnknownType = DefaultUserType,
53-
> = Pick<Attachment<At>, 'actions'> &
54-
Pick<MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'handleAction'> & {
37+
StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics,
38+
> = Pick<Attachment<StreamChatClient>, 'actions'> &
39+
Pick<MessageContextValue<StreamChatClient>, 'handleAction'> & {
5540
styles?: Partial<{
5641
actionButton: StyleProp<ViewStyle>;
5742
buttonText: StyleProp<TextStyle>;
@@ -60,15 +45,9 @@ export type AttachmentActionsPropsWithContext<
6045
};
6146

6247
const AttachmentActionsWithContext = <
63-
At extends UnknownType = DefaultAttachmentType,
64-
Ch extends UnknownType = DefaultChannelType,
65-
Co extends string = DefaultCommandType,
66-
Ev extends UnknownType = DefaultEventType,
67-
Me extends UnknownType = DefaultMessageType,
68-
Re extends UnknownType = DefaultReactionType,
69-
Us extends UnknownType = DefaultUserType,
48+
StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics,
7049
>(
71-
props: AttachmentActionsPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>,
50+
props: AttachmentActionsPropsWithContext<StreamChatClient>,
7251
) => {
7352
const { actions, handleAction, styles: stylesProp = {} } = props;
7453

@@ -137,17 +116,9 @@ const AttachmentActionsWithContext = <
137116
);
138117
};
139118

140-
const areEqual = <
141-
At extends UnknownType = DefaultAttachmentType,
142-
Ch extends UnknownType = DefaultChannelType,
143-
Co extends string = DefaultCommandType,
144-
Ev extends UnknownType = DefaultEventType,
145-
Me extends UnknownType = DefaultMessageType,
146-
Re extends UnknownType = DefaultReactionType,
147-
Us extends UnknownType = DefaultUserType,
148-
>(
149-
prevProps: AttachmentActionsPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>,
150-
nextProps: AttachmentActionsPropsWithContext<At, Ch, Co, Ev, Me, Re, Us>,
119+
const areEqual = <StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics>(
120+
prevProps: AttachmentActionsPropsWithContext<StreamChatClient>,
121+
nextProps: AttachmentActionsPropsWithContext<StreamChatClient>,
151122
) => {
152123
const { actions: prevActions } = prevProps;
153124
const { actions: nextActions } = nextProps;
@@ -163,31 +134,20 @@ const MemoizedAttachmentActions = React.memo(
163134
) as typeof AttachmentActionsWithContext;
164135

165136
export type AttachmentActionsProps<
166-
At extends UnknownType = DefaultAttachmentType,
167-
Ch extends UnknownType = DefaultChannelType,
168-
Co extends string = DefaultCommandType,
169-
Ev extends UnknownType = DefaultEventType,
170-
Me extends UnknownType = DefaultMessageType,
171-
Re extends UnknownType = DefaultReactionType,
172-
Us extends UnknownType = DefaultUserType,
173-
> = Attachment<At> & Partial<Pick<MessageContextValue<At, Ch, Co, Ev, Me, Re, Us>, 'handleAction'>>;
137+
StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics,
138+
> = Attachment<StreamChatClient> &
139+
Partial<Pick<MessageContextValue<StreamChatClient>, 'handleAction'>>;
174140

175141
/**
176142
* AttachmentActions - The actions you can take on an attachment.
177143
* Actions in combination with attachments can be used to build [commands](https://getstream.io/chat/docs/#channel_commands).
178144
*/
179145
export const AttachmentActions = <
180-
At extends UnknownType = DefaultAttachmentType,
181-
Ch extends UnknownType = DefaultChannelType,
182-
Co extends string = DefaultCommandType,
183-
Ev extends UnknownType = DefaultEventType,
184-
Me extends UnknownType = DefaultMessageType,
185-
Re extends UnknownType = DefaultReactionType,
186-
Us extends UnknownType = DefaultUserType,
146+
StreamChatClient extends ExtendableGenerics = DefaultStreamChatGenerics,
187147
>(
188-
props: AttachmentActionsProps<At, Ch, Co, Ev, Me, Re, Us>,
148+
props: AttachmentActionsProps<StreamChatClient>,
189149
) => {
190-
const { handleAction } = useMessageContext<At, Ch, Co, Ev, Me, Re, Us>();
150+
const { handleAction } = useMessageContext<StreamChatClient>();
191151
return <MemoizedAttachmentActions {...{ handleAction }} {...props} />;
192152
};
193153

0 commit comments

Comments
 (0)