Skip to content

Commit 59e62b4

Browse files
authored
feat!: remove deprecated APIs and props from useMessageList and channel unread state (#3318)
Removed deprecated stuff from the message list improvement PR
1 parent 0afc592 commit 59e62b4

File tree

12 files changed

+4
-205
lines changed

12 files changed

+4
-205
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
329329
| 'FlatList'
330330
| 'forceAlignMessages'
331331
| 'Gallery'
332-
| 'getMessagesGroupStyles'
333332
| 'getMessageGroupStyle'
334333
| 'Giphy'
335334
| 'giphyVersion'
@@ -626,7 +625,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
626625
FlatList = NativeHandlers.FlatList,
627626
forceAlignMessages,
628627
Gallery = GalleryDefault,
629-
getMessagesGroupStyles,
630628
getMessageGroupStyle,
631629
Giphy = GiphyDefault,
632630
giphyVersion = 'fixed_height',
@@ -785,6 +783,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
785783
const [threadHasMore, setThreadHasMore] = useState(true);
786784
const [threadLoadingMore, setThreadLoadingMore] = useState(false);
787785
const [channelUnreadStateStore] = useState(new ChannelUnreadStateStore());
786+
// TODO: Think if we can remove this and just rely on the channelUnreadStateStore everywhere.
788787
const setChannelUnreadState = useCallback(
789788
(data: ChannelUnreadStateStoreType['channelUnreadState']) => {
790789
channelUnreadStateStore.channelUnreadState = data;
@@ -1780,7 +1779,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
17801779

17811780
const channelContext = useCreateChannelContext({
17821781
channel,
1783-
channelUnreadState: channelUnreadStateStore.channelUnreadState,
17841782
channelUnreadStateStore,
17851783
disabled: !!channel?.data?.frozen,
17861784
EmptyStateIndicator,
@@ -1930,7 +1928,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
19301928
forceAlignMessages,
19311929
Gallery,
19321930
getMessageGroupStyle,
1933-
getMessagesGroupStyles,
19341931
Giphy,
19351932
giphyVersion,
19361933
handleBan,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { ChannelContextValue } from '../../../contexts/channelContext/Chann
44

55
export const useCreateChannelContext = ({
66
channel,
7-
channelUnreadState,
87
channelUnreadStateStore,
98
disabled,
109
EmptyStateIndicator,
@@ -51,7 +50,6 @@ export const useCreateChannelContext = ({
5150
const channelContext: ChannelContextValue = useMemo(
5251
() => ({
5352
channel,
54-
channelUnreadState,
5553
channelUnreadStateStore,
5654
disabled,
5755
EmptyStateIndicator,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export const useCreateMessagesContext = ({
2828
forceAlignMessages,
2929
Gallery,
3030
getMessageGroupStyle,
31-
getMessagesGroupStyles,
3231
Giphy,
3332
giphyVersion,
3433
handleBan,
@@ -148,7 +147,6 @@ export const useCreateMessagesContext = ({
148147
forceAlignMessages,
149148
Gallery,
150149
getMessageGroupStyle,
151-
getMessagesGroupStyles,
152150
Giphy,
153151
giphyVersion,
154152
handleBan,

package/src/components/MessageList/MessageFlashList.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ type MessageFlashListPropsWithContext = Pick<
104104
Pick<
105105
ChannelContextValue,
106106
| 'channel'
107-
| 'channelUnreadState'
108107
| 'channelUnreadStateStore'
109108
| 'disabled'
110109
| 'EmptyStateIndicator'
@@ -358,7 +357,6 @@ const MessageFlashListWithContext = (props: MessageFlashListPropsWithContext) =>
358357
} = useMessageList({
359358
isFlashList: true,
360359
isLiveStreaming,
361-
noGroupByUser,
362360
threadList,
363361
});
364362

@@ -1129,7 +1127,6 @@ export const MessageFlashList = (props: MessageFlashListProps) => {
11291127
const { closePicker, selectedPicker, setSelectedPicker } = useAttachmentPickerContext();
11301128
const {
11311129
channel,
1132-
channelUnreadState,
11331130
channelUnreadStateStore,
11341131
disabled,
11351132
EmptyStateIndicator,
@@ -1178,7 +1175,6 @@ export const MessageFlashList = (props: MessageFlashListProps) => {
11781175
<MessageFlashListWithContext
11791176
{...{
11801177
channel,
1181-
channelUnreadState,
11821178
channelUnreadStateStore,
11831179
client,
11841180
closePicker,

package/src/components/MessageList/MessageList.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ type MessageListPropsWithContext = Pick<
127127
Pick<
128128
ChannelContextValue,
129129
| 'channel'
130-
| 'channelUnreadState'
131130
| 'channelUnreadStateStore'
132131
| 'disabled'
133132
| 'EmptyStateIndicator'
@@ -327,7 +326,6 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
327326
viewabilityChangedCallback,
328327
} = useMessageList({
329328
isLiveStreaming,
330-
noGroupByUser,
331329
threadList,
332330
});
333331
const messageListLengthBeforeUpdate = useRef(0);
@@ -1214,7 +1212,6 @@ export const MessageList = (props: MessageListProps) => {
12141212
const { closePicker, selectedPicker, setSelectedPicker } = useAttachmentPickerContext();
12151213
const {
12161214
channel,
1217-
channelUnreadState,
12181215
channelUnreadStateStore,
12191216
disabled,
12201217
EmptyStateIndicator,
@@ -1263,7 +1260,6 @@ export const MessageList = (props: MessageListProps) => {
12631260
<MessageListWithContext
12641261
{...{
12651262
channel,
1266-
channelUnreadState,
12671263
channelUnreadStateStore,
12681264
client,
12691265
closePicker,

package/src/components/MessageList/hooks/useMessageList.ts

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { useEffect, useMemo, useRef, useState } from 'react';
1+
import { useEffect, useMemo, useState } from 'react';
22

33
import type { LocalMessage } from 'stream-chat';
44

5-
import { useChannelContext } from '../../../contexts/channelContext/ChannelContext';
65
import { useChatContext } from '../../../contexts/chatContext/ChatContext';
76
import {
87
DeletedMessagesVisibilityType,
@@ -13,15 +12,8 @@ import { useThreadContext } from '../../../contexts/threadContext/ThreadContext'
1312

1413
import { useRAFCoalescedValue } from '../../../hooks';
1514
import { MessagePreviousAndNextMessageStore } from '../../../state-store/message-list-prev-next-state';
16-
import { DateSeparators, getDateSeparators } from '../utils/getDateSeparators';
17-
import { getGroupStyles } from '../utils/getGroupStyles';
1815

1916
export type UseMessageListParams = {
20-
deletedMessagesVisibilityType?: DeletedMessagesVisibilityType;
21-
/**
22-
* @deprecated
23-
*/
24-
noGroupByUser?: boolean;
2517
threadList?: boolean;
2618
isLiveStreaming?: boolean;
2719
isFlashList?: boolean;
@@ -62,11 +54,9 @@ export const shouldIncludeMessageInList = (
6254
};
6355

6456
export const useMessageList = (params: UseMessageListParams) => {
65-
const { noGroupByUser, threadList, isLiveStreaming, isFlashList = false } = params;
57+
const { threadList, isLiveStreaming, isFlashList = false } = params;
6658
const { client } = useChatContext();
67-
const { hideDateSeparators, maxTimeBetweenGroupedMessages } = useChannelContext();
68-
const { deletedMessagesVisibilityType, getMessagesGroupStyles = getGroupStyles } =
69-
useMessagesContext();
59+
const { deletedMessagesVisibilityType } = useMessagesContext();
7060
const { messages, viewabilityChangedCallback } = usePaginatedMessageListContext();
7161
const { threadMessages } = useThreadContext();
7262
const messageList = threadList ? threadMessages : messages;
@@ -101,61 +91,10 @@ export const useMessageList = (params: UseMessageListParams) => {
10191
});
10292
}, [processedMessageList, messageListPreviousAndNextMessageStore, isFlashList]);
10393

104-
/**
105-
* @deprecated use `useDateSeparator` hook instead directly in the Message.
106-
*/
107-
const dateSeparators = useMemo(
108-
() =>
109-
getDateSeparators({
110-
hideDateSeparators,
111-
messages: processedMessageList,
112-
}),
113-
[hideDateSeparators, processedMessageList],
114-
);
115-
116-
/**
117-
* @deprecated use `useDateSeparator` hook instead directly in the Message.
118-
*/
119-
const dateSeparatorsRef = useRef<DateSeparators>(dateSeparators);
120-
dateSeparatorsRef.current = dateSeparators;
121-
122-
/**
123-
* @deprecated use `useMessageGroupStyles` hook instead directly in the Message.
124-
*/
125-
const messageGroupStyles = useMemo(
126-
() =>
127-
getMessagesGroupStyles({
128-
dateSeparators: dateSeparatorsRef.current,
129-
hideDateSeparators,
130-
maxTimeBetweenGroupedMessages,
131-
messages: processedMessageList,
132-
noGroupByUser,
133-
userId: client.userID,
134-
}),
135-
[
136-
getMessagesGroupStyles,
137-
hideDateSeparators,
138-
maxTimeBetweenGroupedMessages,
139-
processedMessageList,
140-
noGroupByUser,
141-
client.userID,
142-
],
143-
);
144-
145-
/**
146-
* @deprecated use `useMessageGroupStyles` hook instead directly in the Message.
147-
*/
148-
const messageGroupStylesRef = useRef<MessageGroupStyles>(messageGroupStyles);
149-
messageGroupStylesRef.current = messageGroupStyles;
150-
15194
const data = useRAFCoalescedValue(processedMessageList, isLiveStreaming);
15295

15396
return useMemo(
15497
() => ({
155-
/** Date separators */
156-
dateSeparatorsRef,
157-
/** Message group styles */
158-
messageGroupStylesRef,
15998
messageListPreviousAndNextMessageStore,
16099
/** Messages enriched with dates/readby/groups and also reversed in order */
161100
processedMessageList: data,

package/src/components/MessageList/utils/getDateSeparators.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

package/src/components/MessageList/utils/getGroupStyles.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { LocalMessage } from 'stream-chat';
22

3-
import type { DateSeparators } from './getDateSeparators';
4-
5-
import type { PaginatedMessageListContextValue } from '../../../contexts/paginatedMessageListContext/PaginatedMessageListContext';
6-
import type { ThreadContextValue } from '../../../contexts/threadContext/ThreadContext';
7-
83
import { isEditedMessage } from '../../../utils/utils';
9-
import type { GroupType } from '../hooks/useMessageList';
104

115
export type MessageGroupStylesParams = {
126
message: LocalMessage;
@@ -17,24 +11,6 @@ export type MessageGroupStylesParams = {
1711
nextMessageDateSeparatorDate?: Date;
1812
};
1913

20-
/**
21-
* @deprecated in favor of `useMessageGroupStyles` hook instead directly in the Message.
22-
*/
23-
export type GetGroupStylesParams = {
24-
dateSeparators: DateSeparators;
25-
messages: PaginatedMessageListContextValue['messages'] | ThreadContextValue['threadMessages'];
26-
/**
27-
* @deprecated in favor of `useDateSeparator` hook instead directly in the Message.
28-
*/
29-
hideDateSeparators?: boolean;
30-
maxTimeBetweenGroupedMessages?: number;
31-
noGroupByUser?: boolean;
32-
/**
33-
* @deprecated
34-
*/
35-
userId?: string;
36-
};
37-
3814
export type GroupStyle = '' | 'middle' | 'top' | 'bottom' | 'single';
3915

4016
/**
@@ -118,34 +94,3 @@ export const getGroupStyle = ({
11894

11995
return groupStyles;
12096
};
121-
122-
/**
123-
* @deprecated in favor of `useMessageGroupStyles` hook instead directly in the Message.
124-
*/
125-
export const getGroupStyles = (params: GetGroupStylesParams) => {
126-
const { dateSeparators, maxTimeBetweenGroupedMessages, messages, noGroupByUser } = params;
127-
128-
if (noGroupByUser) {
129-
return {};
130-
}
131-
132-
const messageGroupStyles: { [key: string]: GroupType[] } = {};
133-
134-
for (let i = 0; i < messages.length; i++) {
135-
const previousMessage = messages[i - 1];
136-
const message = messages[i];
137-
const nextMessage = messages[i + 1];
138-
139-
if (message.id) {
140-
messageGroupStyles[message.id] = getGroupStyle({
141-
dateSeparatorDate: dateSeparators[message.id],
142-
maxTimeBetweenGroupedMessages,
143-
message,
144-
nextMessage,
145-
previousMessage,
146-
});
147-
}
148-
}
149-
150-
return messageGroupStyles;
151-
};

package/src/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ export * from './MessageList/NetworkDownIndicator';
158158
export * from './MessageList/ScrollToBottomButton';
159159
export * from './MessageList/TypingIndicator';
160160
export * from './MessageList/TypingIndicatorContainer';
161-
export * from './MessageList/utils/getDateSeparators';
162161
export * from './MessageList/utils/getGroupStyles';
163162
export * from './MessageList/utils/getLastReceivedMessage';
164163
export * from './Message/hooks/useMessageDeliveryData';

package/src/contexts/channelContext/ChannelContext.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
ChannelUnreadStateStore,
1111
ChannelUnreadStateStoreType,
1212
} from '../../state-store/channel-unread-state';
13-
import { ChannelUnreadState } from '../../types/types';
1413
import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
1514

1615
import { isTestEnvironment } from '../utils/isTestEnvironment';
@@ -135,11 +134,6 @@ export type ChannelContextValue = {
135134
* Its a map of filename and AbortController
136135
*/
137136
uploadAbortControllerRef: React.MutableRefObject<Map<string, AbortController>>;
138-
/**
139-
* Channel unread data
140-
* @deprecated Use channelUnreadStateStore instead
141-
*/
142-
channelUnreadState?: ChannelUnreadState;
143137
channelUnreadStateStore: ChannelUnreadStateStore;
144138
disabled?: boolean;
145139
enableMessageGroupingByUser?: boolean;

0 commit comments

Comments
 (0)