The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/views/room/contextualBar/Threads/useThreadsList.ts

55 lines
1.6 KiB

import { useCallback, useMemo } from 'react';
import { getConfig } from '../../../../../app/ui-utils/client/config';
import { IUser } from '../../../../../definition/IUser';
import { useEndpoint } from '../../../../contexts/ServerContext';
import { useScrollableMessageList } from '../../../../hooks/lists/useScrollableMessageList';
import { useStreamUpdatesForMessageList } from '../../../../hooks/lists/useStreamUpdatesForMessageList';
import { ThreadsList, ThreadsListOptions } from '../../../../lib/lists/ThreadsList';
export const useThreadsList = (
options: ThreadsListOptions,
uid: IUser['_id'],
): {
threadsList: ThreadsList;
initialItemCount: number;
loadMoreItems: (start: number, end: number) => void;
} => {
const threadsList = useMemo(() => new ThreadsList(options), [options]);
const getThreadsList = useEndpoint('GET', 'chat.getThreadsList');
const fetchMessages = useCallback(
async (start, end) => {
const { threads, total } = await getThreadsList({
rid: options.rid,
type: options.type,
text: options.text,
offset: start,
count: end,
});
return {
items: threads,
itemCount: total,
};
},
[getThreadsList, options.rid, options.text, options.type],
);
const { loadMoreItems, initialItemCount } = useScrollableMessageList(
threadsList,
fetchMessages,
useMemo(() => {
const threadsListSize = getConfig('threadsListSize');
return threadsListSize ? parseInt(threadsListSize, 10) : undefined;
}, []),
);
useStreamUpdatesForMessageList(threadsList, uid, options.rid);
return {
threadsList,
loadMoreItems,
initialItemCount,
};
};