Skip to content

Commit 4ad47a1

Browse files
committed
fix: remove MessageType type from the SDK
1 parent ab7973f commit 4ad47a1

Some content is hidden

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

42 files changed

+236
-270
lines changed

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
@@ -169,7 +169,6 @@ import { ShowThreadMessageInChannelButton as ShowThreadMessageInChannelButtonDef
169169
import { StopMessageStreamingButton as DefaultStopMessageStreamingButton } from '../MessageInput/StopMessageStreamingButton';
170170
import { UploadProgressIndicator as UploadProgressIndicatorDefault } from '../MessageInput/UploadProgressIndicator';
171171
import { DateHeader as DateHeaderDefault } from '../MessageList/DateHeader';
172-
import type { MessageType } from '../MessageList/hooks/useMessageList';
173172
import { InlineDateSeparator as InlineDateSeparatorDefault } from '../MessageList/InlineDateSeparator';
174173
import { InlineUnreadIndicator as InlineUnreadIndicatorDefault } from '../MessageList/InlineUnreadIndicator';
175174
import { MessageList as MessageListDefault } from '../MessageList/MessageList';
@@ -684,12 +683,12 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
684683
},
685684
} = useTheme();
686685
const [deleted, setDeleted] = useState<boolean>(false);
687-
const [editing, setEditing] = useState<MessageType | undefined>(undefined);
686+
const [editing, setEditing] = useState<LocalMessage | undefined>(undefined);
688687
const [error, setError] = useState<Error | boolean>(false);
689688
const [lastRead, setLastRead] = useState<Date | undefined>();
690689

691-
const [quotedMessage, setQuotedMessage] = useState<MessageType | undefined>(undefined);
692-
const [thread, setThread] = useState<MessageType | null>(threadProps || null);
690+
const [quotedMessage, setQuotedMessage] = useState<LocalMessage | undefined>(undefined);
691+
const [thread, setThread] = useState<LocalMessage | null>(threadProps || null);
693692
const [threadHasMore, setThreadHasMore] = useState(true);
694693
const [threadLoadingMore, setThreadLoadingMore] = useState(false);
695694
const [channelUnreadState, setChannelUnreadState] = useState<ChannelUnreadState | undefined>(
@@ -1546,7 +1545,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
15461545
const updatedMessage = {
15471546
...message,
15481547
cid: channel.cid,
1549-
deleted_at: new Date().toISOString(),
1548+
deleted_at: new Date(),
15501549
type: 'deleted' as MessageLabel,
15511550
};
15521551
updateMessage(updatedMessage);
@@ -1998,7 +1997,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
19981997

19991998
export type ChannelProps = Partial<Omit<ChannelPropsWithContext, 'channel' | 'thread'>> &
20001999
Pick<ChannelPropsWithContext, 'channel'> & {
2001-
thread?: MessageType | ThreadType | null;
2000+
thread?: LocalMessage | ThreadType | null;
20022001
};
20032002

20042003
/**
@@ -2017,7 +2016,7 @@ export const Channel = (props: PropsWithChildren<ChannelProps>) => {
20172016
const threadInstance = (threadFromProps as ThreadType)?.threadInstance as Thread;
20182017
const threadMessage = (
20192018
threadInstance ? (threadFromProps as ThreadType).thread : threadFromProps
2020-
) as MessageType;
2019+
) as LocalMessage;
20212020

20222021
const thread: ThreadType = {
20232022
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
>

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

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

88
import { fireEvent, render, 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 { generateImageAttachment } from '../../../mock-builders/generator/attach
2022
import { generateMessage } from '../../../mock-builders/generator/message';
2123
import { getTestClientWithUser } from '../../../mock-builders/mock';
2224

23-
import type { MessageType } from '../../MessageList/hooks/useMessageList';
2425
import { ImageGalleryOverlay } from '../components/ImageGalleryOverlay';
2526

2627
describe('ImageGalleryOverlay', () => {
@@ -39,7 +40,7 @@ describe('ImageGalleryOverlay', () => {
3940
generateMessage({
4041
attachments: [generateImageAttachment()],
4142
}),
42-
] as unknown as MessageType[],
43+
] as unknown as LocalMessage[],
4344
} as unknown as ImageGalleryContextValue
4445
}
4546
>

0 commit comments

Comments
 (0)