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
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { act } from 'react-test-renderer';

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

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

describe('ImageGalleryOverlay', () => {
Expand All @@ -39,7 +40,7 @@ describe('ImageGalleryOverlay', () => {
generateMessage({
attachments: [generateImageAttachment()],
}),
] as unknown as MessageType[],
] as unknown as LocalMessage[],
} as unknown as ImageGalleryContextValue
}
>
Expand Down
Loading
Loading