Skip to content

Commit bc3d3fe

Browse files
committed
feat: add a way to override query channels
1 parent 2eb9c02 commit bc3d3fe

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

package/src/components/ChannelList/ChannelList.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import React, { useEffect, useMemo, useState } from 'react';
22

33
import type { FlatList } from 'react-native-gesture-handler';
44

5-
import { Channel, ChannelFilters, ChannelOptions, ChannelSort, Event } from 'stream-chat';
5+
import {
6+
Channel,
7+
ChannelFilters,
8+
ChannelOptions,
9+
ChannelSort,
10+
Event,
11+
QueryChannelsRequestType,
12+
} from 'stream-chat';
613

714
import { ChannelListFooterLoadingIndicator } from './ChannelListFooterLoadingIndicator';
815
import { ChannelListHeaderErrorIndicator } from './ChannelListHeaderErrorIndicator';
@@ -215,6 +222,15 @@ export type ChannelListProps = Partial<
215222
* @see See [Channel query documentation](https://getstream.io/chat/docs/query_channels) for a list of available sorting fields
216223
* */
217224
sort?: ChannelSort;
225+
226+
/**
227+
* A function that overrides the default ChannelManager queryChannels method, which is StreamChat.queryChannels.
228+
* It is particularly useful whenever we want to pass specific cids that we want to query but also want to
229+
* paginate over them (which is not possible through normal filters). It comes with with several rules/assumptions:
230+
* - StreamChat.queryChannels has to be called inside of queryChannelsOverride (as it updates important client state)
231+
* - The return type has to be Channel[] (which is the return type of StreamChat.queryChannels)
232+
*/
233+
queryChannelsOverride?: QueryChannelsRequestType;
218234
};
219235

220236
const DEFAULT_FILTERS = {};
@@ -268,6 +284,7 @@ export const ChannelList = (props: ChannelListProps) => {
268284
setFlatListRef,
269285
Skeleton = SkeletonDefault,
270286
sort = DEFAULT_SORT,
287+
queryChannelsOverride,
271288
} = props;
272289

273290
const [forceUpdate, setForceUpdate] = useState(0);
@@ -319,6 +336,12 @@ export const ChannelList = (props: ChannelListProps) => {
319336
sort,
320337
]);
321338

339+
useEffect(() => {
340+
if (queryChannelsOverride) {
341+
channelManager.setQueryChannelsRequest(queryChannelsOverride);
342+
}
343+
}, [channelManager, queryChannelsOverride]);
344+
322345
useEffect(() => {
323346
channelManager.setOptions({ abortInFlightQuery: false, lockChannelOrder });
324347
}, [channelManager, lockChannelOrder]);

0 commit comments

Comments
 (0)