Skip to content

Commit e6f700c

Browse files
authored
feat: add prop for helping multiple channel list implementation (#1951)
* feat: add guide * feat: add a prop for passing a custom channal list filtering function * chore: update yarn locks of example apps * chore: update yarn locks of example apps * fix: prettier warnings
1 parent cf80c90 commit e6f700c

File tree

7 files changed

+49
-21
lines changed

7 files changed

+49
-21
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
id: multiple channel lists
3+
sidebar_position: 12
4+
title: Multiple Channel Lists
5+
---
6+
7+
This example will focus on the specific use case where there are two `ChannelList` components in the same application.
8+
9+
The event listeners of both lists, let's say A and B, will pick up all `new.message` events for every channel, regardless of which list the `message` is sent in. If a message is sent in list B, the event listener in list A will also pick up the new `message` and bump the impacted `channel` to the top of the list. This is not the desired result for multiple lists, but there is a correct way to handle the routing of these messages.
10+
11+
## channelRenderFilterFn prop
12+
13+
The reason that a channel will automatically be bumped to the top of a list even though it's not part of the list is due to the default behavior. The ChannelList components will retrieve a channel from `client.activeChannels` if the channel doesn't already exist.
14+
15+
By using the `channelRenderFilterFn` prop we can apply custom filtering logic to the list of channels that are rendered. Since we have access to the entire channel object, we can filter on type, custom fields, or others.
16+
17+
```tsx
18+
const customChannelFilterFunction = (channels: Channel[]) => {
19+
return channels.filter(/** your custom filter logic */);
20+
};
21+
22+
<ChannelList channelRenderFilterFn={customChannelFilterFunction} filters={filters} />;
23+
```

examples/ExpoMessaging/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6665,10 +6665,10 @@ [email protected]:
66656665
version "0.0.0"
66666666
uid ""
66676667

6668-
6669-
version "5.9.0"
6670-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
6671-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
6668+
6669+
version "5.9.1"
6670+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
6671+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
66726672
dependencies:
66736673
"@babel/runtime" "^7.12.5"
66746674
"@gorhom/bottom-sheet" "4.4.5"

examples/SampleApp/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7598,10 +7598,10 @@ [email protected]:
75987598
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4"
75997599
integrity sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg==
76007600

7601-
7602-
version "5.9.0"
7603-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
7604-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
7601+
7602+
version "5.9.1"
7603+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
7604+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
76057605
dependencies:
76067606
"@babel/runtime" "^7.12.5"
76077607
"@gorhom/bottom-sheet" "4.4.5"

examples/TypeScriptMessaging/yarn.lock

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

7164-
7165-
version "5.9.0"
7166-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
7167-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
7164+
7165+
version "5.9.1"
7166+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
7167+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
71687168
dependencies:
71697169
"@babel/runtime" "^7.12.5"
71707170
"@gorhom/bottom-sheet" "4.4.5"

package/expo-package/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,10 +2998,10 @@ [email protected]:
29982998
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4"
29992999
integrity sha512-uyQK/mx5QjHun80FLJTfaWE7JtwfRMKBLkMne6udYOmvH0CawotVa7TfgYHzAnpphn4+TweIx1QKMnRIbipmUg==
30003000

3001-
3002-
version "5.9.0"
3003-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
3004-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
3001+
3002+
version "5.9.1"
3003+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
3004+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
30053005
dependencies:
30063006
"@babel/runtime" "^7.12.5"
30073007
"@gorhom/bottom-sheet" "4.4.5"

package/native-package/yarn.lock

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

4406-
4407-
version "5.9.0"
4408-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.0.tgz#a226a1f9d629d1f3e212df1f2a46312c544bc0bb"
4409-
integrity sha512-goG9dyDpVopspGt3gq31ILkwEzdolo0+CdhcpVeGmOB2CZ0tF9X78uByrj4/7VsqpCkC0hi4uMSEsERM3DZdbg==
4406+
4407+
version "5.9.1"
4408+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-5.9.1.tgz#c496feb6905e391505adca37c2eef25712a6e6d7"
4409+
integrity sha512-3zWEaoOHNpGAHy7qEI1PFqdx3dq3oHSpEs+PBrHYuUi8Xj7NisKWYkXkK3sa0BSn0hwcduSMZmNGOO9oo9lj2g==
44104410
dependencies:
44114411
"@babel/runtime" "^7.12.5"
44124412
"@gorhom/bottom-sheet" "4.4.5"

package/src/components/ChannelList/ChannelList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export type ChannelListProps<
6161
| 'numberOfSkeletons'
6262
>
6363
> & {
64+
/** Optional function to filter channels prior to rendering the list. Do not use any complex logic that would delay the loading of the ChannelList. We recommend using a pure function with array methods like filter/sort/reduce. */
65+
channelRenderFilterFn?: (
66+
channels: Array<Channel<StreamChatGenerics>>,
67+
) => Array<Channel<StreamChatGenerics>>;
6468
/**
6569
* Object containing channel query filters
6670
*
@@ -236,6 +240,7 @@ export const ChannelList = <
236240
) => {
237241
const {
238242
additionalFlatListProps = {},
243+
channelRenderFilterFn,
239244
EmptyStateIndicator = EmptyStateIndicatorDefault,
240245
FooterLoadingIndicator = ChannelListFooterLoadingIndicator,
241246
filters = DEFAULT_FILTERS,
@@ -365,7 +370,7 @@ export const ChannelList = <
365370

366371
const channelsContext = useCreateChannelsContext({
367372
additionalFlatListProps,
368-
channels,
373+
channels: channelRenderFilterFn ? channelRenderFilterFn(channels ?? []) : channels,
369374
EmptyStateIndicator,
370375
error,
371376
FooterLoadingIndicator,

0 commit comments

Comments
 (0)