Skip to content

Commit ba1df1d

Browse files
authored
Merge pull request #3064 from GetStream/remove-messagetype-type
fix: remove MessageType type from the SDK
2 parents e14c614 + cc33ccb commit ba1df1d

Some content is hidden

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

51 files changed

+315
-419
lines changed

examples/SampleApp/App.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { createStackNavigator } from '@react-navigation/stack';
66
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
77
import {
88
Chat,
9-
MessageType,
109
OverlayProvider,
1110
SqliteClient,
1211
ThemeProvider,
@@ -36,7 +35,7 @@ import { SharedGroupsScreen } from './src/screens/SharedGroupsScreen';
3635
import { ThreadScreen } from './src/screens/ThreadScreen';
3736
import { UserSelectorScreen } from './src/screens/UserSelectorScreen';
3837

39-
import type { StreamChat } from 'stream-chat';
38+
import type { LocalMessage, StreamChat } from 'stream-chat';
4039

4140
if (__DEV__) {
4241
DevSettings.addMenuItem('Reset local DB (offline storage)', () => {
@@ -45,10 +44,7 @@ if (__DEV__) {
4544
});
4645
}
4746

48-
import type {
49-
StackNavigatorParamList,
50-
UserSelectorParamList,
51-
} from './src/types';
47+
import type { StackNavigatorParamList, UserSelectorParamList } from './src/types';
5248
import { GestureHandlerRootView } from 'react-native-gesture-handler';
5349
import { navigateToChannel, RootNavigationRef } from './src/utils/RootNavigation';
5450
import FastImage from 'react-native-fast-image';
@@ -106,18 +102,16 @@ const App = () => {
106102
}
107103
}
108104
});
109-
messaging
110-
.getInitialNotification()
111-
.then((remoteMessage) => {
112-
if (remoteMessage) {
113-
// Notification caused app to open from quit state on iOS
114-
const channelId = remoteMessage.data?.channel_id as string;
115-
if (channelId) {
116-
// this will make the app to start with the channel screen with this channel id
117-
initialChannelIdGlobalRef.current = channelId;
118-
}
105+
messaging.getInitialNotification().then((remoteMessage) => {
106+
if (remoteMessage) {
107+
// Notification caused app to open from quit state on iOS
108+
const channelId = remoteMessage.data?.channel_id as string;
109+
if (channelId) {
110+
// this will make the app to start with the channel screen with this channel id
111+
initialChannelIdGlobalRef.current = channelId;
119112
}
120-
});
113+
}
114+
});
121115
return () => {
122116
unsubscribeOnNotificationOpen();
123117
unsubscribeForegroundEvent();
@@ -170,7 +164,7 @@ const DrawerNavigator: React.FC = () => (
170164
</Drawer.Navigator>
171165
);
172166

173-
const isMessageAIGenerated = (message: MessageType) => !!message.ai_generated;
167+
const isMessageAIGenerated = (message: LocalMessage) => !!message.ai_generated;
174168

175169
const DrawerNavigatorWrapper: React.FC<{
176170
chatClient: StreamChat;

examples/SampleApp/src/screens/ThreadScreen.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { StyleSheet, View } from 'react-native';
33
import { SafeAreaView } from 'react-native-safe-area-context';
44
import {
55
Channel,
6-
MessageType,
76
Thread,
87
ThreadType,
98
useAttachmentPickerContext,
@@ -17,7 +16,7 @@ import { ScreenHeader } from '../components/ScreenHeader';
1716
import type { RouteProp } from '@react-navigation/native';
1817

1918
import type { StackNavigatorParamList } from '../types';
20-
import { ThreadState, UserResponse } from 'stream-chat';
19+
import { LocalMessage, ThreadState, UserResponse } from 'stream-chat';
2120

2221
const selector = (nextValue: ThreadState) => ({ parentMessage: nextValue.parentMessage }) as const;
2322

@@ -34,12 +33,12 @@ type ThreadScreenProps = {
3433
};
3534

3635
export type ThreadHeaderProps = {
37-
thread: MessageType | ThreadType;
36+
thread: LocalMessage | ThreadType;
3837
};
3938

4039
const ThreadHeader: React.FC<ThreadHeaderProps> = ({ thread }) => {
4140
const typing = useTypingString();
42-
let subtitleText = ((thread as MessageType)?.user as UserResponse)?.name;
41+
let subtitleText = ((thread as LocalMessage)?.user as UserResponse)?.name;
4342
const { parentMessage } =
4443
useStateStore((thread as ThreadType)?.threadInstance?.state, selector) || {};
4544

examples/SampleApp/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Channel, UserResponse } from 'stream-chat';
2-
import type { MessageType, ThreadType } from 'stream-chat-react-native';
1+
import type { Channel, LocalMessage, UserResponse } from 'stream-chat';
2+
import type { ThreadType } from 'stream-chat-react-native';
33
import type { Theme } from '@react-navigation/native';
44

55
export type DrawerNavigatorParamList = {
@@ -38,7 +38,7 @@ export type StackNavigatorParamList = {
3838
};
3939
ThreadScreen: {
4040
channel: Channel;
41-
thread: MessageType | ThreadType;
41+
thread: LocalMessage | ThreadType;
4242
};
4343
};
4444

package/src/components/Attachment/Gallery.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useMemo } from 'react';
22
import { Pressable, StyleSheet, Text, View } from 'react-native';
33

4-
import type { Attachment } from 'stream-chat';
4+
import type { Attachment, LocalMessage } from 'stream-chat';
55

66
import { GalleryImage } from './GalleryImage';
77
import { ImageReloadIndicator } from './ImageReloadIndicator';
@@ -12,7 +12,6 @@ import { getGalleryImageBorderRadius } from './utils/getGalleryImageBorderRadius
1212

1313
import { openUrlSafely } from './utils/openUrlSafely';
1414

15-
import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
1615
import { useChatConfigContext } from '../../contexts/chatConfigContext/ChatConfigContext';
1716
import {
1817
ImageGalleryContextValue,
@@ -76,7 +75,7 @@ export type GalleryPropsWithContext = Pick<
7675
*
7776
* TODO: Fix circular dependencies of imports
7877
*/
79-
message?: MessageType;
78+
message?: LocalMessage;
8079
};
8180

8281
const GalleryWithContext = (props: GalleryPropsWithContext) => {
@@ -241,7 +240,7 @@ type GalleryThumbnailProps = {
241240
colIndex: number;
242241
imagesAndVideos: Attachment[];
243242
invertedDirections: boolean;
244-
message: MessageType;
243+
message: LocalMessage;
245244
numOfColumns: number;
246245
numOfRows: number;
247246
rowIndex: number;

package/src/components/Channel/Channel.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ import { ShowThreadMessageInChannelButton as ShowThreadMessageInChannelButtonDef
170170
import { StopMessageStreamingButton as DefaultStopMessageStreamingButton } from '../MessageInput/StopMessageStreamingButton';
171171
import { UploadProgressIndicator as UploadProgressIndicatorDefault } from '../MessageInput/UploadProgressIndicator';
172172
import { DateHeader as DateHeaderDefault } from '../MessageList/DateHeader';
173-
import type { MessageType } from '../MessageList/hooks/useMessageList';
174173
import { InlineDateSeparator as InlineDateSeparatorDefault } from '../MessageList/InlineDateSeparator';
175174
import { InlineUnreadIndicator as InlineUnreadIndicatorDefault } from '../MessageList/InlineUnreadIndicator';
176175
import { MessageList as MessageListDefault } from '../MessageList/MessageList';
@@ -685,12 +684,12 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
685684
},
686685
} = useTheme();
687686
const [deleted, setDeleted] = useState<boolean>(false);
688-
const [editing, setEditing] = useState<MessageType | undefined>(undefined);
687+
const [editing, setEditing] = useState<LocalMessage | undefined>(undefined);
689688
const [error, setError] = useState<Error | boolean>(false);
690689
const [lastRead, setLastRead] = useState<Date | undefined>();
691690

692-
const [quotedMessage, setQuotedMessage] = useState<MessageType | undefined>(undefined);
693-
const [thread, setThread] = useState<MessageType | null>(threadProps || null);
691+
const [quotedMessage, setQuotedMessage] = useState<LocalMessage | undefined>(undefined);
692+
const [thread, setThread] = useState<LocalMessage | null>(threadProps || null);
694693
const [threadHasMore, setThreadHasMore] = useState(true);
695694
const [threadLoadingMore, setThreadLoadingMore] = useState(false);
696695
const [channelUnreadState, setChannelUnreadState] = useState<ChannelUnreadState | undefined>(
@@ -1583,7 +1582,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
15831582
const updatedMessage = {
15841583
...message,
15851584
cid: channel.cid,
1586-
deleted_at: new Date().toISOString(),
1585+
deleted_at: new Date(),
15871586
type: 'deleted' as MessageLabel,
15881587
};
15891588
updateMessage(updatedMessage);
@@ -2035,7 +2034,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
20352034

20362035
export type ChannelProps = Partial<Omit<ChannelPropsWithContext, 'channel' | 'thread'>> &
20372036
Pick<ChannelPropsWithContext, 'channel'> & {
2038-
thread?: MessageType | ThreadType | null;
2037+
thread?: LocalMessage | ThreadType | null;
20392038
};
20402039

20412040
/**
@@ -2054,7 +2053,7 @@ export const Channel = (props: PropsWithChildren<ChannelProps>) => {
20542053
const threadInstance = (threadFromProps as ThreadType)?.threadInstance as Thread;
20552054
const threadMessage = (
20562055
threadInstance ? (threadFromProps as ThreadType).thread : threadFromProps
2057-
) as MessageType;
2056+
) as LocalMessage;
20582057

20592058
const thread: ThreadType = {
20602059
thread: threadMessage,

package/src/components/Channel/hooks/useChannelDataState.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { useCallback, useState } from 'react';
22

3-
import { Channel, ChannelState as StreamChannelState } from 'stream-chat';
4-
5-
import { MessageType } from '../../MessageList/hooks/useMessageList';
3+
import { Channel, LocalMessage, ChannelState as StreamChannelState } from 'stream-chat';
64

75
export const channelInitialState = {
86
hasMore: true,
@@ -38,7 +36,7 @@ export type ChannelMessagesState = {
3836
* The ChannelThreadState object
3937
*/
4038
export type ChannelThreadState = {
41-
thread: MessageType | null;
39+
thread: LocalMessage | null;
4240
threadHasMore?: boolean;
4341
threadLoadingMore?: boolean;
4442
threadMessages?: StreamChannelState['messages'];

package/src/components/Chat/Chat.tsx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,6 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
308308
* - connectionRecovering - whether or not websocket is reconnecting
309309
* - isOnline - whether or not set user is active
310310
* - setActiveChannel - function to set the currently active channel
311-
*
312-
* The Chat Component takes the following generics in order:
313-
* - At (AttachmentType) - custom Attachment object extension
314-
* - Ct (ChannelType) - custom Channel object extension
315-
* - Co (CommandType) - custom Command string union extension
316-
* - Ev (EventType) - custom Event object extension
317-
* - Me (MessageType) - custom Message object extension
318-
* - Re (ReactionType) - custom Reaction object extension
319-
* - Us (UserType) - custom User object extension
320311
*/
321312
export const Chat = (props: PropsWithChildren<ChatProps>) => {
322313
const { style } = useOverlayContext();

package/src/components/ImageGallery/__tests__/ImageGallery.test.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type { SharedValue } from 'react-native-reanimated';
44

55
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react-native';
66

7+
import { LocalMessage } from 'stream-chat';
8+
79
import {
810
ImageGalleryContext,
911
ImageGalleryContextValue,
@@ -18,7 +20,6 @@ import {
1820
} from '../../../mock-builders/generator/attachment';
1921
import { generateMessage } from '../../../mock-builders/generator/message';
2022

21-
import type { MessageType } from '../../MessageList/hooks/useMessageList';
2223
import { ImageGallery } from '../ImageGallery';
2324

2425
jest.mock('../../../native.ts', () => {
@@ -56,7 +57,7 @@ describe('ImageGallery', () => {
5657
generateVideoAttachment({ type: 'video' }),
5758
],
5859
}),
59-
] as unknown as MessageType[],
60+
] as unknown as LocalMessage[],
6061
}),
6162
);
6263

@@ -73,7 +74,7 @@ describe('ImageGallery', () => {
7374
});
7475
render(
7576
getComponent({
76-
messages: [message] as unknown as MessageType[],
77+
messages: [message] as unknown as LocalMessage[],
7778
}),
7879
);
7980

@@ -102,7 +103,7 @@ describe('ImageGallery', () => {
102103
generateMessage({
103104
attachments: [generateVideoAttachment({ type: 'video' })],
104105
}),
105-
] as unknown as MessageType[],
106+
] as unknown as LocalMessage[],
106107
}),
107108
);
108109

@@ -128,7 +129,7 @@ describe('ImageGallery', () => {
128129

129130
render(
130131
getComponent({
131-
messages: [message] as unknown as MessageType[],
132+
messages: [message] as unknown as LocalMessage[],
132133
}),
133134
);
134135

@@ -163,7 +164,7 @@ describe('ImageGallery', () => {
163164
generateMessage({
164165
attachments: [generateVideoAttachment({ type: 'video' })],
165166
}),
166-
] as unknown as MessageType[],
167+
] as unknown as LocalMessage[],
167168
}),
168169
);
169170

@@ -193,7 +194,7 @@ describe('ImageGallery', () => {
193194
});
194195
render(
195196
getComponent({
196-
messages: [message] as unknown as MessageType[],
197+
messages: [message] as unknown as LocalMessage[],
197198
}),
198199
);
199200

package/src/components/ImageGallery/__tests__/ImageGalleryFooter.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { ReactTestInstance } from 'react-test-renderer';
77

88
import { render, screen, userEvent, waitFor } from '@testing-library/react-native';
99

10+
import { LocalMessage } from 'stream-chat';
11+
1012
import { Chat } from '../../../components/Chat/Chat';
1113
import {
1214
ImageGalleryContext,
@@ -20,7 +22,6 @@ import {
2022
import { generateMessage } from '../../../mock-builders/generator/message';
2123
import { getTestClientWithUser } from '../../../mock-builders/mock';
2224
import { NativeHandlers } from '../../../native';
23-
import type { MessageType } from '../../MessageList/hooks/useMessageList';
2425
import { ImageGallery, ImageGalleryCustomComponents } from '../ImageGallery';
2526

2627
jest.mock('../../../native.ts', () => {
@@ -76,7 +77,7 @@ describe('ImageGalleryFooter', () => {
7677
generateMessage({
7778
attachments: [generateVideoAttachment({ type: 'video' })],
7879
}),
79-
] as unknown as MessageType[],
80+
] as unknown as LocalMessage[],
8081
} as unknown as ImageGalleryContextValue
8182
}
8283
>
@@ -131,7 +132,7 @@ describe('ImageGalleryFooter', () => {
131132
generateMessage({
132133
attachments: [generateVideoAttachment({ type: 'video' })],
133134
}),
134-
] as unknown as MessageType[],
135+
] as unknown as LocalMessage[],
135136
} as unknown as ImageGalleryContextValue
136137
}
137138
>
@@ -174,7 +175,7 @@ describe('ImageGalleryFooter', () => {
174175
generateMessage({
175176
attachments: [generateImageAttachment()],
176177
}),
177-
] as unknown as MessageType[],
178+
] as unknown as LocalMessage[],
178179
} as unknown as ImageGalleryContextValue
179180
}
180181
>

package/src/components/ImageGallery/__tests__/ImageGalleryHeader.test.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { act } from 'react-test-renderer';
77

88
import { render, screen, userEvent, waitFor } from '@testing-library/react-native';
99

10+
import { LocalMessage } from 'stream-chat';
11+
1012
import { Chat } from '../../../components/Chat/Chat';
1113
import {
1214
ImageGalleryContext,
@@ -24,7 +26,6 @@ import {
2426
import { generateMessage } from '../../../mock-builders/generator/message';
2527
import { getTestClientWithUser } from '../../../mock-builders/mock';
2628

27-
import type { MessageType } from '../../MessageList/hooks/useMessageList';
2829
import { ImageGallery, ImageGalleryCustomComponents } from '../ImageGallery';
2930

3031
jest.mock('../../../native.ts', () => {
@@ -71,7 +72,7 @@ describe('ImageGalleryHeader', () => {
7172
generateMessage({
7273
attachments: [generateImageAttachment()],
7374
}),
74-
] as unknown as MessageType[],
75+
] as unknown as LocalMessage[],
7576
} as unknown as ImageGalleryContextValue
7677
}
7778
>
@@ -118,7 +119,7 @@ describe('ImageGalleryHeader', () => {
118119
generateMessage({
119120
attachments: [generateVideoAttachment({ type: 'video' })],
120121
}),
121-
] as unknown as MessageType[],
122+
] as unknown as LocalMessage[],
122123
} as unknown as ImageGalleryContextValue
123124
}
124125
>
@@ -158,7 +159,7 @@ describe('ImageGalleryHeader', () => {
158159
generateMessage({
159160
attachments: [generateImageAttachment()],
160161
}),
161-
] as unknown as MessageType[],
162+
] as unknown as LocalMessage[],
162163
} as unknown as ImageGalleryContextValue
163164
}
164165
>

0 commit comments

Comments
 (0)