Skip to content

Commit 252cac3

Browse files
authored
feat: allow complete channel list throttled reload on internet connection recovery (#2123)
1 parent acf0621 commit 252cac3

File tree

4 files changed

+394
-92
lines changed

4 files changed

+394
-92
lines changed

docusaurus/docs/React/components/core-components/channel-list.mdx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,39 @@ Custom UI component to display the channel preview in the list.
357357
| --------- | ---------------------------------------------------------------------------------------------------- |
358358
| component | <GHComponentLink text='ChannelPreviewMessenger' path='/ChannelPreview/ChannelPreviewMessenger.tsx'/> |
359359

360+
### recoveryThrottleIntervalMs
361+
362+
Custom interval during which the recovery channel list queries will be prevented. This is to avoid firing unnecessary queries during internet connection fluctuation. Recovery channel query is triggered upon internet connection recovery and leads to complete channel list reload with pagination offset 0. The minimum throttle interval is 2000ms. The default throttle interval is 5000ms.
363+
364+
The channel list recovery mechanism described here (applying `recoveryThrottleIntervalMs`) **is activated only if the `StreamChat` client's channel list recovery mechanism is disabled**. The `StreamChat` recovery mechanism can be disabled when initiating the client instance through the `options` parameter:
365+
366+
```typescript jsx
367+
import { StreamChat } from 'stream-chat';
368+
import { ChannelList, Chat } from 'stream-chat-react';
369+
370+
// ... get apiKey, filters, sort, options
371+
372+
const client = new StreamChat(apiKey, {recoverStateOnReconnect: false});
373+
const App = () => (
374+
<Chat client={client} >
375+
{/** ... */}
376+
<ChannelList
377+
filters={filters}
378+
sort={sort}
379+
options={options}
380+
recoveryThrottleIntervalMs={3000}
381+
{/** other props... */}
382+
/>
383+
{/** ... */}
384+
</Chat>
385+
);
386+
387+
```
388+
389+
| Type | Default |
390+
|--------|---------|
391+
| number | 5000 |
392+
360393
### renderChannels
361394

362395
Function to override the default behavior when rendering channels, so this function is called instead of rendering the Preview directly.

src/components/ChannelList/ChannelList.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ export type ChannelListProps<
121121
Paginator?: React.ComponentType<PaginatorProps | LoadMorePaginatorProps>;
122122
/** Custom UI component to display the channel preview in the list, defaults to and accepts same props as: [ChannelPreviewMessenger](https://github.com/GetStream/stream-chat-react/blob/master/src/components/ChannelPreview/ChannelPreviewMessenger.tsx) */
123123
Preview?: React.ComponentType<ChannelPreviewUIComponentProps<StreamChatGenerics>>;
124+
/**
125+
* Custom interval during which the recovery channel list queries will be prevented.
126+
* This is to avoid firing unnecessary queries during internet connection fluctuation.
127+
* Recovery channel query is triggered upon `connection.recovered` and leads to complete channel list reload with pagination offset 0.
128+
* The minimum throttle interval is 2000ms. The default throttle interval is 5000ms.
129+
*/
130+
recoveryThrottleIntervalMs?: number;
124131
/** Function to override the default behavior when rendering channels, so this function is called instead of rendering the Preview directly */
125132
renderChannels?: (
126133
channels: Channel<StreamChatGenerics>[],
@@ -167,6 +174,7 @@ const UnMemoizedChannelList = <
167174
options,
168175
Paginator = LoadMorePaginator,
169176
Preview,
177+
recoveryThrottleIntervalMs,
170178
renderChannels,
171179
sendChannelsToList = false,
172180
setActiveChannelOnMount = true,
@@ -256,6 +264,7 @@ const UnMemoizedChannelList = <
256264
sort || DEFAULT_SORT,
257265
options || DEFAULT_OPTIONS,
258266
activeChannelHandler,
267+
recoveryThrottleIntervalMs,
259268
);
260269

261270
const loadedChannels = channelRenderFilterFn ? channelRenderFilterFn(channels) : channels;

0 commit comments

Comments
 (0)