Skip to content

Commit deca714

Browse files
authored
Merge pull request #3176 from GetStream/feat/query-channels-override-prop
feat: add a way to override query channels
2 parents 2eb9c02 + 9c15eb4 commit deca714

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

examples/SampleApp/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7922,10 +7922,10 @@ [email protected]:
79227922
version "0.0.0"
79237923
uid ""
79247924

7925-
stream-chat@^9.11.0:
7926-
version "9.11.0"
7927-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.11.0.tgz#412b5f2f55cc3b76e862d88cb3e95b9720493575"
7928-
integrity sha512-mnf86LMBPmCZUrmrU6bdaOUoxRqpXUvw7prl4b5q6WPNWZ+p/41UN8vllBAaZvAS7jPj9JYWvbhUe40VZ6o8/g==
7925+
stream-chat@^9.12.0:
7926+
version "9.12.0"
7927+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.12.0.tgz#d27b1319844d100ca419c61463f5c65f53c87952"
7928+
integrity sha512-/A4y8jBmWdP53RUY9f8dlc8dRjC/irR5KUMiOhn0IiAEmK2fKuD/7IpUzXi7cNmR8QMxlHdDMJZdB2wMDkiskQ==
79297929
dependencies:
79307930
"@types/jsonwebtoken" "^9.0.8"
79317931
"@types/ws" "^8.5.14"

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"path": "0.12.7",
7979
"react-native-markdown-package": "1.8.2",
8080
"react-native-url-polyfill": "^2.0.0",
81-
"stream-chat": "^9.11.0",
81+
"stream-chat": "^9.12.0",
8282
"use-sync-external-store": "^1.5.0"
8383
},
8484
"peerDependencies": {

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]);

package/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8314,10 +8314,10 @@ statuses@~1.5.0:
83148314
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
83158315
integrity sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==
83168316

8317-
stream-chat@^9.11.0:
8318-
version "9.11.0"
8319-
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.11.0.tgz#412b5f2f55cc3b76e862d88cb3e95b9720493575"
8320-
integrity sha512-mnf86LMBPmCZUrmrU6bdaOUoxRqpXUvw7prl4b5q6WPNWZ+p/41UN8vllBAaZvAS7jPj9JYWvbhUe40VZ6o8/g==
8317+
stream-chat@^9.12.0:
8318+
version "9.12.0"
8319+
resolved "https://registry.yarnpkg.com/stream-chat/-/stream-chat-9.12.0.tgz#d27b1319844d100ca419c61463f5c65f53c87952"
8320+
integrity sha512-/A4y8jBmWdP53RUY9f8dlc8dRjC/irR5KUMiOhn0IiAEmK2fKuD/7IpUzXi7cNmR8QMxlHdDMJZdB2wMDkiskQ==
83218321
dependencies:
83228322
"@types/jsonwebtoken" "^9.0.8"
83238323
"@types/ws" "^8.5.14"

0 commit comments

Comments
 (0)