Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ describe('useMessageListPagination', () => {

await waitFor(() => {
expect(queryFn).toHaveBeenCalledWith({
messages: { id_lt: messages[0].id, limit: 10 },
messages: { id_lt: messages[0].id, limit: 25 },
watchers: {
limit: 10,
limit: 25,
},
});
expect(result.current.state.hasMore).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const useMessageListPagination = ({ channel }: { channel: Channel }) => {
/**
* This function loads more messages before the first message in current channel state.
*/
const loadMore = useStableCallback(async (limit: number = 10) => {
const loadMore = useStableCallback(async (limit: number = 25) => {
if (!channel.state.messagePagination.hasPrev) {
return;
}
Expand Down
19 changes: 14 additions & 5 deletions package/src/components/MessageList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type MessageListPropsWithContext = Pick<
| 'maximumMessageLimit'
> &
Pick<ChatContextValue, 'client'> &
Pick<PaginatedMessageListContextValue, 'loadMore' | 'loadMoreRecent'> &
Pick<PaginatedMessageListContextValue, 'loadMore' | 'loadMoreRecent' | 'hasMore'> &
Pick<
MessagesContextValue,
| 'DateHeader'
Expand All @@ -190,7 +190,7 @@ type MessageListPropsWithContext = Pick<
Pick<MessageInputContextValue, 'messageInputFloating' | 'messageInputHeightStore'> &
Pick<
ThreadContextValue,
'loadMoreRecentThread' | 'loadMoreThread' | 'thread' | 'threadInstance'
'loadMoreRecentThread' | 'loadMoreThread' | 'threadHasMore' | 'thread' | 'threadInstance'
> & {
/**
* Besides existing (default) UX behavior of underlying FlatList of MessageList component, if you want
Expand Down Expand Up @@ -325,6 +325,8 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
TypingIndicator,
TypingIndicatorContainer,
UnreadMessagesNotification,
hasMore,
threadHasMore,
} = props;
const [isUnreadNotificationOpen, setIsUnreadNotificationOpen] = useState<boolean>(false);
const { theme } = useTheme();
Expand Down Expand Up @@ -914,8 +916,12 @@ const MessageListWithContext = (props: MessageListPropsWithContext) => {
* 3. If the call to `loadMoreRecent` is in progress, we wait for it to finish to make sure scroll doesn't jump.
*/
const maybeCallOnEndReached = useStableCallback(async () => {
const shouldQuery = (threadList && threadHasMore) || (!threadList && hasMore);
// If onEndReached has already been called for given messageList length, then ignore.
if (processedMessageList?.length && onEndReachedTracker.current[processedMessageList.length]) {
if (
(processedMessageList?.length && onEndReachedTracker.current[processedMessageList.length]) ||
!shouldQuery
) {
return;
}

Expand Down Expand Up @@ -1332,8 +1338,9 @@ export const MessageList = (props: MessageListProps) => {
UnreadMessagesNotification,
} = useMessagesContext();
const { messageInputFloating, messageInputHeightStore } = useMessageInputContext();
const { loadMore, loadMoreRecent } = usePaginatedMessageListContext();
const { loadMoreRecentThread, loadMoreThread, thread, threadInstance } = useThreadContext();
const { loadMore, loadMoreRecent, hasMore } = usePaginatedMessageListContext();
const { loadMoreRecentThread, loadMoreThread, threadHasMore, thread, threadInstance } =
useThreadContext();

return (
<MessageListWithContext
Expand Down Expand Up @@ -1384,6 +1391,8 @@ export const MessageList = (props: MessageListProps) => {
TypingIndicator,
TypingIndicatorContainer,
UnreadMessagesNotification,
hasMore,
threadHasMore,
}}
{...props}
noGroupByUser={!enableMessageGroupingByUser || props.noGroupByUser}
Expand Down