stream-chat-react-native-core 8.12.4 → 8.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/Channel/Channel.js +1 -1
- package/lib/commonjs/components/Channel/Channel.js.map +1 -1
- package/lib/commonjs/components/Channel/hooks/useMessageListPagination.js +69 -61
- package/lib/commonjs/components/Channel/hooks/useMessageListPagination.js.map +1 -1
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js +1 -7
- package/lib/commonjs/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/commonjs/components/MessageList/MessageList.js +40 -6
- package/lib/commonjs/components/MessageList/MessageList.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Channel/Channel.js +1 -1
- package/lib/module/components/Channel/Channel.js.map +1 -1
- package/lib/module/components/Channel/hooks/useMessageListPagination.js +69 -61
- package/lib/module/components/Channel/hooks/useMessageListPagination.js.map +1 -1
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js +1 -7
- package/lib/module/components/ChannelList/hooks/usePaginatedChannels.js.map +1 -1
- package/lib/module/components/MessageList/MessageList.js +40 -6
- package/lib/module/components/MessageList/MessageList.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Channel/Channel.d.ts.map +1 -1
- package/lib/typescript/components/Channel/hooks/useMessageListPagination.d.ts.map +1 -1
- package/lib/typescript/components/ChannelList/hooks/usePaginatedChannels.d.ts.map +1 -1
- package/lib/typescript/components/MessageList/MessageList.d.ts +1 -1
- package/lib/typescript/components/MessageList/MessageList.d.ts.map +1 -1
- package/lib/typescript/hooks/useTranslatedMessage.d.ts +1 -0
- package/lib/typescript/hooks/useTranslatedMessage.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/components/Channel/Channel.tsx +2 -1
- package/src/components/Channel/__tests__/useMessageListPagination.test.js +4 -4
- package/src/components/Channel/hooks/useMessageListPagination.tsx +2 -2
- package/src/components/ChannelList/hooks/usePaginatedChannels.ts +1 -8
- package/src/components/MessageList/MessageList.tsx +59 -8
- package/src/version.json +1 -1
|
@@ -161,8 +161,8 @@ describe('useMessageListPagination', () => {
|
|
|
161
161
|
|
|
162
162
|
await waitFor(() => {
|
|
163
163
|
expect(queryFn).toHaveBeenCalledWith({
|
|
164
|
-
messages: { id_lt: messages[0].id
|
|
165
|
-
watchers: {
|
|
164
|
+
messages: { id_lt: messages[0].id },
|
|
165
|
+
watchers: {},
|
|
166
166
|
});
|
|
167
167
|
expect(result.current.state.hasMore).toBe(true);
|
|
168
168
|
expect(result.current.state.messages.length).toBe(40);
|
|
@@ -252,8 +252,8 @@ describe('useMessageListPagination', () => {
|
|
|
252
252
|
|
|
253
253
|
await waitFor(() => {
|
|
254
254
|
expect(queryFn).toHaveBeenCalledWith({
|
|
255
|
-
messages: { id_gt: messages[messages.length - 1].id
|
|
256
|
-
watchers: {
|
|
255
|
+
messages: { id_gt: messages[messages.length - 1].id },
|
|
256
|
+
watchers: {},
|
|
257
257
|
});
|
|
258
258
|
expect(result.current.state.hasMore).toBe(true);
|
|
259
259
|
expect(result.current.state.messages.length).toBe(40);
|
|
@@ -74,7 +74,7 @@ export const useMessageListPagination = ({ channel }: { channel: Channel }) => {
|
|
|
74
74
|
/**
|
|
75
75
|
* This function loads more messages before the first message in current channel state.
|
|
76
76
|
*/
|
|
77
|
-
const loadMore = useStableCallback(async (limit
|
|
77
|
+
const loadMore = useStableCallback(async (limit?: number) => {
|
|
78
78
|
if (!channel.state.messagePagination.hasPrev) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
@@ -103,7 +103,7 @@ export const useMessageListPagination = ({ channel }: { channel: Channel }) => {
|
|
|
103
103
|
/**
|
|
104
104
|
* This function loads more messages after the most recent message in current channel state.
|
|
105
105
|
*/
|
|
106
|
-
const loadMoreRecent = useStableCallback(async (limit
|
|
106
|
+
const loadMoreRecent = useStableCallback(async (limit?: number) => {
|
|
107
107
|
if (!channel.state.messagePagination.hasNext) {
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
@@ -13,8 +13,6 @@ import { useChatContext } from '../../../contexts/chatContext/ChatContext';
|
|
|
13
13
|
import { useStateStore } from '../../../hooks';
|
|
14
14
|
import { useIsMountedRef } from '../../../hooks/useIsMountedRef';
|
|
15
15
|
|
|
16
|
-
import { MAX_QUERY_CHANNELS_LIMIT } from '../utils';
|
|
17
|
-
|
|
18
16
|
type Parameters = {
|
|
19
17
|
channelManager: ChannelManager;
|
|
20
18
|
enableOfflineSupport: boolean;
|
|
@@ -24,10 +22,6 @@ type Parameters = {
|
|
|
24
22
|
sort: ChannelSort;
|
|
25
23
|
};
|
|
26
24
|
|
|
27
|
-
const DEFAULT_OPTIONS = {
|
|
28
|
-
message_limit: 10,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
25
|
const RETRY_INTERVAL_IN_MS = 5000;
|
|
32
26
|
|
|
33
27
|
type QueryType = 'queryLocalDB' | 'reload' | 'refresh' | 'loadChannels';
|
|
@@ -46,7 +40,7 @@ export const usePaginatedChannels = ({
|
|
|
46
40
|
channelManager,
|
|
47
41
|
enableOfflineSupport,
|
|
48
42
|
filters = {},
|
|
49
|
-
options =
|
|
43
|
+
options = {},
|
|
50
44
|
sort = {},
|
|
51
45
|
}: Parameters) => {
|
|
52
46
|
const [staticChannelsActive, setStaticChannelsActive] = useState<boolean>(false);
|
|
@@ -99,7 +93,6 @@ export const usePaginatedChannels = ({
|
|
|
99
93
|
setActiveQueryType(queryType);
|
|
100
94
|
|
|
101
95
|
const newOptions = {
|
|
102
|
-
limit: options?.limit ?? MAX_QUERY_CHANNELS_LIMIT,
|
|
103
96
|
offset: 0,
|
|
104
97
|
...options,
|
|
105
98
|
};
|
|
@@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
2
2
|
import {
|
|
3
3
|
FlatListProps,
|
|
4
4
|
FlatList as FlatListType,
|
|
5
|
+
LayoutChangeEvent,
|
|
5
6
|
ScrollViewProps,
|
|
6
7
|
StyleSheet,
|
|
7
8
|
View,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
ViewToken,
|
|
10
11
|
} from 'react-native';
|
|
11
12
|
|
|
13
|
+
import debounce from 'lodash/debounce';
|
|
12
14
|
import type { Channel, Event, LocalMessage, MessageResponse } from 'stream-chat';
|
|
13
15
|
|
|
14
16
|
import { useMessageList } from './hooks/useMessageList';
|
|
@@ -148,7 +150,7 @@ type MessageListPropsWithContext = Pick<
|
|
|
148
150
|
> &
|
|
149
151
|
Pick<ChatContextValue, 'client'> &
|
|
150
152
|
Pick<ImageGalleryContextValue, 'setMessages'> &
|
|
151
|
-
Pick<PaginatedMessageListContextValue, 'loadMore' | 'loadMoreRecent'> &
|
|
153
|
+
Pick<PaginatedMessageListContextValue, 'loadMore' | 'loadMoreRecent' | 'hasMore'> &
|
|
152
154
|
Pick<
|
|
153
155
|
MessagesContextValue,
|
|
154
156
|
| 'DateHeader'
|
|
@@ -163,7 +165,7 @@ type MessageListPropsWithContext = Pick<
|
|
|
163
165
|
> &
|
|
164
166
|
Pick<
|
|
165
167
|
ThreadContextValue,
|
|
166
|
-
'loadMoreRecentThread' | 'loadMoreThread' | 'thread' | 'threadInstance'
|
|
168
|
+
'loadMoreRecentThread' | 'loadMoreThread' | 'threadHasMore' | 'thread' | 'threadInstance'
|
|
167
169
|
> & {
|
|
168
170
|
/**
|
|
169
171
|
* Besides existing (default) UX behavior of underlying FlatList of MessageList component, if you want
|
|
@@ -295,6 +297,8 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
295
297
|
TypingIndicator,
|
|
296
298
|
TypingIndicatorContainer,
|
|
297
299
|
UnreadMessagesNotification,
|
|
300
|
+
hasMore,
|
|
301
|
+
threadHasMore,
|
|
298
302
|
} = props;
|
|
299
303
|
const [isUnreadNotificationOpen, setIsUnreadNotificationOpen] = useState<boolean>(false);
|
|
300
304
|
const { theme } = useTheme();
|
|
@@ -327,8 +331,8 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
327
331
|
|
|
328
332
|
const renderItem = useCallback(
|
|
329
333
|
({ item: message, index }: { item: LocalMessage; index: number }) => {
|
|
330
|
-
const previousMessage =
|
|
331
|
-
const nextMessage =
|
|
334
|
+
const previousMessage = processedMessageList[index + 1];
|
|
335
|
+
const nextMessage = processedMessageList[index - 1];
|
|
332
336
|
return (
|
|
333
337
|
<MessageWrapper
|
|
334
338
|
message={message}
|
|
@@ -337,7 +341,7 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
337
341
|
/>
|
|
338
342
|
);
|
|
339
343
|
},
|
|
340
|
-
[
|
|
344
|
+
[processedMessageList],
|
|
341
345
|
);
|
|
342
346
|
|
|
343
347
|
const messageListLengthBeforeUpdate = useRef(0);
|
|
@@ -856,8 +860,12 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
856
860
|
* 3. If the call to `loadMoreRecent` is in progress, we wait for it to finish to make sure scroll doesn't jump.
|
|
857
861
|
*/
|
|
858
862
|
const maybeCallOnEndReached = useStableCallback(async () => {
|
|
863
|
+
const shouldQuery = (threadList && threadHasMore) || (!threadList && hasMore);
|
|
859
864
|
// If onEndReached has already been called for given messageList length, then ignore.
|
|
860
|
-
if (
|
|
865
|
+
if (
|
|
866
|
+
(processedMessageList?.length && onEndReachedTracker.current[processedMessageList.length]) ||
|
|
867
|
+
!shouldQuery
|
|
868
|
+
) {
|
|
861
869
|
return;
|
|
862
870
|
}
|
|
863
871
|
|
|
@@ -1126,6 +1134,44 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
1126
1134
|
[additionalFlatListProps?.contentContainerStyle, contentContainer],
|
|
1127
1135
|
);
|
|
1128
1136
|
|
|
1137
|
+
const viewportHeightRef = useRef<number>(undefined);
|
|
1138
|
+
|
|
1139
|
+
/**
|
|
1140
|
+
* This debounced callback makes sure that if the current number of messages do not
|
|
1141
|
+
* fill our screen, we load more messages continuously until we cover enough ground.
|
|
1142
|
+
*/
|
|
1143
|
+
const debouncedPrefillMessages = useMemo(
|
|
1144
|
+
() =>
|
|
1145
|
+
debounce(
|
|
1146
|
+
(viewportHeight: number, contentHeight: number) => {
|
|
1147
|
+
if (viewportHeight >= contentHeight) {
|
|
1148
|
+
maybeCallOnEndReached();
|
|
1149
|
+
}
|
|
1150
|
+
},
|
|
1151
|
+
500,
|
|
1152
|
+
{
|
|
1153
|
+
leading: false,
|
|
1154
|
+
trailing: true,
|
|
1155
|
+
},
|
|
1156
|
+
),
|
|
1157
|
+
[maybeCallOnEndReached],
|
|
1158
|
+
);
|
|
1159
|
+
|
|
1160
|
+
const onContentSizeChange = useStableCallback((width: number, height: number) => {
|
|
1161
|
+
if (additionalFlatListProps?.onContentSizeChange) {
|
|
1162
|
+
additionalFlatListProps.onContentSizeChange(width, height);
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
debouncedPrefillMessages(viewportHeightRef.current ?? 0, height);
|
|
1166
|
+
});
|
|
1167
|
+
|
|
1168
|
+
const onLayout = useStableCallback((event: LayoutChangeEvent) => {
|
|
1169
|
+
if (additionalFlatListProps?.onLayout) {
|
|
1170
|
+
additionalFlatListProps.onLayout(event);
|
|
1171
|
+
}
|
|
1172
|
+
viewportHeightRef.current = event.nativeEvent.layout.height;
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1129
1175
|
if (!FlatList) {
|
|
1130
1176
|
return null;
|
|
1131
1177
|
}
|
|
@@ -1168,6 +1214,8 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
|
|
|
1168
1214
|
*/
|
|
1169
1215
|
maintainVisibleContentPosition={maintainVisibleContentPosition}
|
|
1170
1216
|
maxToRenderPerBatch={30}
|
|
1217
|
+
onContentSizeChange={onContentSizeChange}
|
|
1218
|
+
onLayout={onLayout}
|
|
1171
1219
|
onMomentumScrollEnd={onUserScrollEvent}
|
|
1172
1220
|
onScroll={handleScroll}
|
|
1173
1221
|
onScrollBeginDrag={onScrollBeginDrag}
|
|
@@ -1259,8 +1307,9 @@ export const MessageList = (props: MessageListProps) => {
|
|
|
1259
1307
|
TypingIndicatorContainer,
|
|
1260
1308
|
UnreadMessagesNotification,
|
|
1261
1309
|
} = useMessagesContext();
|
|
1262
|
-
const { loadMore, loadMoreRecent } = usePaginatedMessageListContext();
|
|
1263
|
-
const { loadMoreRecentThread, loadMoreThread, thread, threadInstance } =
|
|
1310
|
+
const { loadMore, loadMoreRecent, hasMore } = usePaginatedMessageListContext();
|
|
1311
|
+
const { loadMoreRecentThread, loadMoreThread, threadHasMore, thread, threadInstance } =
|
|
1312
|
+
useThreadContext();
|
|
1264
1313
|
|
|
1265
1314
|
return (
|
|
1266
1315
|
<MessageListWithContext
|
|
@@ -1277,6 +1326,7 @@ export const MessageList = (props: MessageListProps) => {
|
|
|
1277
1326
|
enableMessageGroupingByUser,
|
|
1278
1327
|
error,
|
|
1279
1328
|
FlatList,
|
|
1329
|
+
hasMore,
|
|
1280
1330
|
hideStickyDateHeader,
|
|
1281
1331
|
highlightedMessageId,
|
|
1282
1332
|
InlineDateSeparator,
|
|
@@ -1309,6 +1359,7 @@ export const MessageList = (props: MessageListProps) => {
|
|
|
1309
1359
|
StickyHeader,
|
|
1310
1360
|
targetedMessage,
|
|
1311
1361
|
thread,
|
|
1362
|
+
threadHasMore,
|
|
1312
1363
|
threadInstance,
|
|
1313
1364
|
threadList,
|
|
1314
1365
|
TypingIndicator,
|
package/src/version.json
CHANGED