Skip to content

fix: remove MessageType type from the SDK #3064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions examples/SampleApp/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { createStackNavigator } from '@react-navigation/stack';
import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context';
import {
Chat,
MessageType,
OverlayProvider,
SqliteClient,
ThemeProvider,
Expand Down Expand Up @@ -36,7 +35,7 @@ import { SharedGroupsScreen } from './src/screens/SharedGroupsScreen';
import { ThreadScreen } from './src/screens/ThreadScreen';
import { UserSelectorScreen } from './src/screens/UserSelectorScreen';

import type { StreamChat } from 'stream-chat';
import type { LocalMessage, StreamChat } from 'stream-chat';

if (__DEV__) {
DevSettings.addMenuItem('Reset local DB (offline storage)', () => {
Expand All @@ -45,10 +44,7 @@ if (__DEV__) {
});
}

import type {
StackNavigatorParamList,
UserSelectorParamList,
} from './src/types';
import type { StackNavigatorParamList, UserSelectorParamList } from './src/types';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { navigateToChannel, RootNavigationRef } from './src/utils/RootNavigation';
import FastImage from 'react-native-fast-image';
Expand Down Expand Up @@ -106,18 +102,16 @@ const App = () => {
}
}
});
messaging
.getInitialNotification()
.then((remoteMessage) => {
if (remoteMessage) {
// Notification caused app to open from quit state on iOS
const channelId = remoteMessage.data?.channel_id as string;
if (channelId) {
// this will make the app to start with the channel screen with this channel id
initialChannelIdGlobalRef.current = channelId;
}
messaging.getInitialNotification().then((remoteMessage) => {
if (remoteMessage) {
// Notification caused app to open from quit state on iOS
const channelId = remoteMessage.data?.channel_id as string;
if (channelId) {
// this will make the app to start with the channel screen with this channel id
initialChannelIdGlobalRef.current = channelId;
}
});
}
});
return () => {
unsubscribeOnNotificationOpen();
unsubscribeForegroundEvent();
Expand Down Expand Up @@ -170,7 +164,7 @@ const DrawerNavigator: React.FC = () => (
</Drawer.Navigator>
);

const isMessageAIGenerated = (message: MessageType) => !!message.ai_generated;
const isMessageAIGenerated = (message: LocalMessage) => !!message.ai_generated;

const DrawerNavigatorWrapper: React.FC<{
chatClient: StreamChat;
Expand Down
7 changes: 3 additions & 4 deletions examples/SampleApp/src/screens/ThreadScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { StyleSheet, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import {
Channel,
MessageType,
Thread,
ThreadType,
useAttachmentPickerContext,
Expand All @@ -17,7 +16,7 @@ import { ScreenHeader } from '../components/ScreenHeader';
import type { RouteProp } from '@react-navigation/native';

import type { StackNavigatorParamList } from '../types';
import { ThreadState, UserResponse } from 'stream-chat';
import { LocalMessage, ThreadState, UserResponse } from 'stream-chat';

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

Expand All @@ -34,12 +33,12 @@ type ThreadScreenProps = {
};

export type ThreadHeaderProps = {
thread: MessageType | ThreadType;
thread: LocalMessage | ThreadType;
};

const ThreadHeader: React.FC<ThreadHeaderProps> = ({ thread }) => {
const typing = useTypingString();
let subtitleText = ((thread as MessageType)?.user as UserResponse)?.name;
let subtitleText = ((thread as LocalMessage)?.user as UserResponse)?.name;
const { parentMessage } =
useStateStore((thread as ThreadType)?.threadInstance?.state, selector) || {};

Expand Down
6 changes: 3 additions & 3 deletions examples/SampleApp/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Channel, UserResponse } from 'stream-chat';
import type { MessageType, ThreadType } from 'stream-chat-react-native';
import type { Channel, LocalMessage, UserResponse } from 'stream-chat';
import type { ThreadType } from 'stream-chat-react-native';
import type { Theme } from '@react-navigation/native';

export type DrawerNavigatorParamList = {
Expand Down Expand Up @@ -38,7 +38,7 @@ export type StackNavigatorParamList = {
};
ThreadScreen: {
channel: Channel;
thread: MessageType | ThreadType;
thread: LocalMessage | ThreadType;
};
};

Expand Down
7 changes: 3 additions & 4 deletions package/src/components/Attachment/Gallery.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import { Pressable, StyleSheet, Text, View } from 'react-native';

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

import { GalleryImage } from './GalleryImage';
import { ImageReloadIndicator } from './ImageReloadIndicator';
Expand All @@ -12,7 +12,6 @@ import { getGalleryImageBorderRadius } from './utils/getGalleryImageBorderRadius

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

import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
import { useChatConfigContext } from '../../contexts/chatConfigContext/ChatConfigContext';
import {
ImageGalleryContextValue,
Expand Down Expand Up @@ -76,7 +75,7 @@ export type GalleryPropsWithContext = Pick<
*
* TODO: Fix circular dependencies of imports
*/
message?: MessageType;
message?: LocalMessage;
};

const GalleryWithContext = (props: GalleryPropsWithContext) => {
Expand Down Expand Up @@ -241,7 +240,7 @@ type GalleryThumbnailProps = {
colIndex: number;
imagesAndVideos: Attachment[];
invertedDirections: boolean;
message: MessageType;
message: LocalMessage;
numOfColumns: number;
numOfRows: number;
rowIndex: number;
Expand Down
13 changes: 6 additions & 7 deletions package/src/components/Channel/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ import { ShowThreadMessageInChannelButton as ShowThreadMessageInChannelButtonDef
import { StopMessageStreamingButton as DefaultStopMessageStreamingButton } from '../MessageInput/StopMessageStreamingButton';
import { UploadProgressIndicator as UploadProgressIndicatorDefault } from '../MessageInput/UploadProgressIndicator';
import { DateHeader as DateHeaderDefault } from '../MessageList/DateHeader';
import type { MessageType } from '../MessageList/hooks/useMessageList';
import { InlineDateSeparator as InlineDateSeparatorDefault } from '../MessageList/InlineDateSeparator';
import { InlineUnreadIndicator as InlineUnreadIndicatorDefault } from '../MessageList/InlineUnreadIndicator';
import { MessageList as MessageListDefault } from '../MessageList/MessageList';
Expand Down Expand Up @@ -685,12 +684,12 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
},
} = useTheme();
const [deleted, setDeleted] = useState<boolean>(false);
const [editing, setEditing] = useState<MessageType | undefined>(undefined);
const [editing, setEditing] = useState<LocalMessage | undefined>(undefined);
const [error, setError] = useState<Error | boolean>(false);
const [lastRead, setLastRead] = useState<Date | undefined>();

const [quotedMessage, setQuotedMessage] = useState<MessageType | undefined>(undefined);
const [thread, setThread] = useState<MessageType | null>(threadProps || null);
const [quotedMessage, setQuotedMessage] = useState<LocalMessage | undefined>(undefined);
const [thread, setThread] = useState<LocalMessage | null>(threadProps || null);
const [threadHasMore, setThreadHasMore] = useState(true);
const [threadLoadingMore, setThreadLoadingMore] = useState(false);
const [channelUnreadState, setChannelUnreadState] = useState<ChannelUnreadState | undefined>(
Expand Down Expand Up @@ -1583,7 +1582,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
const updatedMessage = {
...message,
cid: channel.cid,
deleted_at: new Date().toISOString(),
deleted_at: new Date(),
type: 'deleted' as MessageLabel,
};
updateMessage(updatedMessage);
Expand Down Expand Up @@ -2035,7 +2034,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =

export type ChannelProps = Partial<Omit<ChannelPropsWithContext, 'channel' | 'thread'>> &
Pick<ChannelPropsWithContext, 'channel'> & {
thread?: MessageType | ThreadType | null;
thread?: LocalMessage | ThreadType | null;
};

/**
Expand All @@ -2054,7 +2053,7 @@ export const Channel = (props: PropsWithChildren<ChannelProps>) => {
const threadInstance = (threadFromProps as ThreadType)?.threadInstance as Thread;
const threadMessage = (
threadInstance ? (threadFromProps as ThreadType).thread : threadFromProps
) as MessageType;
) as LocalMessage;

const thread: ThreadType = {
thread: threadMessage,
Expand Down
6 changes: 2 additions & 4 deletions package/src/components/Channel/hooks/useChannelDataState.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useCallback, useState } from 'react';

import { Channel, ChannelState as StreamChannelState } from 'stream-chat';

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

export const channelInitialState = {
hasMore: true,
Expand Down Expand Up @@ -38,7 +36,7 @@ export type ChannelMessagesState = {
* The ChannelThreadState object
*/
export type ChannelThreadState = {
thread: MessageType | null;
thread: LocalMessage | null;
threadHasMore?: boolean;
threadLoadingMore?: boolean;
threadMessages?: StreamChannelState['messages'];
Expand Down
9 changes: 0 additions & 9 deletions package/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,6 @@ const ChatWithContext = (props: PropsWithChildren<ChatProps>) => {
* - connectionRecovering - whether or not websocket is reconnecting
* - isOnline - whether or not set user is active
* - setActiveChannel - function to set the currently active channel
*
* The Chat Component takes the following generics in order:
* - At (AttachmentType) - custom Attachment object extension
* - Ct (ChannelType) - custom Channel object extension
* - Co (CommandType) - custom Command string union extension
* - Ev (EventType) - custom Event object extension
* - Me (MessageType) - custom Message object extension
* - Re (ReactionType) - custom Reaction object extension
* - Us (UserType) - custom User object extension
*/
export const Chat = (props: PropsWithChildren<ChatProps>) => {
const { style } = useOverlayContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { SharedValue } from 'react-native-reanimated';

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

import { LocalMessage } from 'stream-chat';

import {
ImageGalleryContext,
ImageGalleryContextValue,
Expand All @@ -18,7 +20,6 @@ import {
} from '../../../mock-builders/generator/attachment';
import { generateMessage } from '../../../mock-builders/generator/message';

import type { MessageType } from '../../MessageList/hooks/useMessageList';
import { ImageGallery } from '../ImageGallery';

jest.mock('../../../native.ts', () => {
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('ImageGallery', () => {
generateVideoAttachment({ type: 'video' }),
],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
}),
);

Expand All @@ -73,7 +74,7 @@ describe('ImageGallery', () => {
});
render(
getComponent({
messages: [message] as unknown as MessageType[],
messages: [message] as unknown as LocalMessage[],
}),
);

Expand Down Expand Up @@ -102,7 +103,7 @@ describe('ImageGallery', () => {
generateMessage({
attachments: [generateVideoAttachment({ type: 'video' })],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
}),
);

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

render(
getComponent({
messages: [message] as unknown as MessageType[],
messages: [message] as unknown as LocalMessage[],
}),
);

Expand Down Expand Up @@ -163,7 +164,7 @@ describe('ImageGallery', () => {
generateMessage({
attachments: [generateVideoAttachment({ type: 'video' })],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
}),
);

Expand Down Expand Up @@ -193,7 +194,7 @@ describe('ImageGallery', () => {
});
render(
getComponent({
messages: [message] as unknown as MessageType[],
messages: [message] as unknown as LocalMessage[],
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { ReactTestInstance } from 'react-test-renderer';

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

import { LocalMessage } from 'stream-chat';

import { Chat } from '../../../components/Chat/Chat';
import {
ImageGalleryContext,
Expand All @@ -20,7 +22,6 @@ import {
import { generateMessage } from '../../../mock-builders/generator/message';
import { getTestClientWithUser } from '../../../mock-builders/mock';
import { NativeHandlers } from '../../../native';
import type { MessageType } from '../../MessageList/hooks/useMessageList';
import { ImageGallery, ImageGalleryCustomComponents } from '../ImageGallery';

jest.mock('../../../native.ts', () => {
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('ImageGalleryFooter', () => {
generateMessage({
attachments: [generateVideoAttachment({ type: 'video' })],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
} as unknown as ImageGalleryContextValue
}
>
Expand Down Expand Up @@ -131,7 +132,7 @@ describe('ImageGalleryFooter', () => {
generateMessage({
attachments: [generateVideoAttachment({ type: 'video' })],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
} as unknown as ImageGalleryContextValue
}
>
Expand Down Expand Up @@ -174,7 +175,7 @@ describe('ImageGalleryFooter', () => {
generateMessage({
attachments: [generateImageAttachment()],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
} as unknown as ImageGalleryContextValue
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { act } from 'react-test-renderer';

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

import { LocalMessage } from 'stream-chat';

import { Chat } from '../../../components/Chat/Chat';
import {
ImageGalleryContext,
Expand All @@ -24,7 +26,6 @@ import {
import { generateMessage } from '../../../mock-builders/generator/message';
import { getTestClientWithUser } from '../../../mock-builders/mock';

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

jest.mock('../../../native.ts', () => {
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('ImageGalleryHeader', () => {
generateMessage({
attachments: [generateImageAttachment()],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
} as unknown as ImageGalleryContextValue
}
>
Expand Down Expand Up @@ -118,7 +119,7 @@ describe('ImageGalleryHeader', () => {
generateMessage({
attachments: [generateVideoAttachment({ type: 'video' })],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
} as unknown as ImageGalleryContextValue
}
>
Expand Down Expand Up @@ -158,7 +159,7 @@ describe('ImageGalleryHeader', () => {
generateMessage({
attachments: [generateImageAttachment()],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
} as unknown as ImageGalleryContextValue
}
>
Expand Down
Loading