Skip to content

Commit a98a771

Browse files
authored
Merge pull request #1175 from GetStream/channellist-hooks-additions
add allowNewMessagesFromUnfilteredChannels argument to channellist hooks
2 parents 24f08ab + 1de4ebb commit a98a771

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## [6.7.2](https://github.com/GetStream/stream-chat-react/releases/tag/v6.7.2) 2021-09-15
4+
5+
### Feature
6+
7+
- Add optional `allowNewMessagesFromUnfilteredChannels` argument to `useNotificationMessageNewListener` and `useNotificationAddedToChannelListener` hooks to prevent channel from incrementing the list [#1175](https://github.com/GetStream/stream-chat-react/pull/1175)
8+
9+
### Bug
10+
11+
- Fix issue with autocomplete mentions displaying muted users [#1171](https://github.com/GetStream/stream-chat-react/pull/1171)
12+
- Prevent user mention edge case crash [#1172](https://github.com/GetStream/stream-chat-react/pull/1172)
13+
- Fix reaction handler edge case on mobile web use case [#1173](https://github.com/GetStream/stream-chat-react/pull/1173)
14+
- Add missing default value for `publishTypingEvent` `MessageInput` prop [#1174](https://github.com/GetStream/stream-chat-react/pull/1174)
15+
316
## [6.7.1](https://github.com/GetStream/stream-chat-react/releases/tag/v6.7.1) 2021-09-14
417

518
### Bug

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,10 @@ Additional props to be passed to the underlying [`ChannelSearch`](../utility-com
102102

103103
### allowNewMessagesFromUnfilteredChannels
104104

105-
When the client receives a `message.new` event, we automatically push that channel to the top of the list. If the channel
106-
doesn't currently exist in the list, we grab the channel from `client.activeChannels` and push it to the top of the list.
107-
You can disable this behavior by setting this prop to false, which will prevent channels not in the list from incrementing the list.
105+
When the client receives `message.new`, `notification.message_new`, and `notification.added_to_channel` events, we automatically push
106+
that channel to the top of the list. If the channel doesn't currently exist in the list, we grab the channel from `client.activeChannels`
107+
and push it to the top of the list. You can disable this behavior by setting this prop to false, which will prevent channels not in the
108+
list from incrementing the list.
108109

109110
| Type | Default |
110111
| ------- | ------- |

src/components/ChannelList/ChannelList.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ export type ChannelListProps<
6262
/** Additional props for underlying ChannelSearch component, [available props](https://getstream.io/chat/docs/sdk/react/utility-components/channel_search/#props) */
6363
additionalChannelSearchProps?: ChannelSearchProps<At, Ch, Co, Ev, Me, Re, Us>;
6464
/**
65-
* When the client receives a `message.new` event, we automatically push that channel to the top of the list.
66-
* If the channel doesn't currently exist in the list, we grab the channel from `client.activeChannels`
67-
* and push it to the top of the list. You can disable this behavior by setting this prop
65+
* When the client receives `message.new`, `notification.message_new`, and `notification.added_to_channel` events, we automatically
66+
* push that channel to the top of the list. If the channel doesn't currently exist in the list, we grab the channel from
67+
* `client.activeChannels` and push it to the top of the list. You can disable this behavior by setting this prop
6868
* to false, which will prevent channels not in the list from incrementing the list. The default is true.
6969
*/
7070
allowNewMessagesFromUnfilteredChannels?: boolean;
@@ -270,8 +270,17 @@ const UnMemoizedChannelList = <
270270
useMobileNavigation(channelListRef, navOpen, closeMobileNav);
271271

272272
useMessageNewListener(setChannels, lockChannelOrder, allowNewMessagesFromUnfilteredChannels);
273-
useNotificationMessageNewListener(setChannels, onMessageNew, setOffset);
274-
useNotificationAddedToChannelListener(setChannels, onAddedToChannel);
273+
useNotificationMessageNewListener(
274+
setChannels,
275+
onMessageNew,
276+
setOffset,
277+
allowNewMessagesFromUnfilteredChannels,
278+
);
279+
useNotificationAddedToChannelListener(
280+
setChannels,
281+
onAddedToChannel,
282+
allowNewMessagesFromUnfilteredChannels,
283+
);
275284
useNotificationRemovedFromChannelListener(setChannels, onRemovedFromChannel);
276285
useChannelDeletedListener(setChannels, onChannelDeleted);
277286
useChannelHiddenListener(setChannels, onChannelHidden);

src/components/ChannelList/hooks/useNotificationAddedToChannelListener.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ export const useNotificationAddedToChannelListener = <
3131
setChannels: React.Dispatch<React.SetStateAction<Array<Channel<At, Ch, Co, Ev, Me, Re, Us>>>>,
3232
event: Event<At, Ch, Co, Ev, Me, Re, Us>,
3333
) => void,
34+
allowNewMessagesFromUnfilteredChannels = true,
3435
) => {
3536
const { client } = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
3637

3738
useEffect(() => {
3839
const handleEvent = async (event: Event<At, Ch, Co, Ev, Me, Re, Us>) => {
3940
if (customHandler && typeof customHandler === 'function') {
4041
customHandler(setChannels, event);
41-
} else if (event.channel?.type) {
42+
} else if (allowNewMessagesFromUnfilteredChannels && event.channel?.type) {
4243
const channel = await getChannel(client, event.channel.type, event.channel.id);
4344
setChannels((channels) => uniqBy([channel, ...channels], 'cid'));
4445
}

src/components/ChannelList/hooks/useNotificationMessageNewListener.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,16 @@ export const useNotificationMessageNewListener = <
3232
event: Event<At, Ch, Co, Ev, Me, Re, Us>,
3333
) => void,
3434
setOffset?: React.Dispatch<React.SetStateAction<number>>,
35+
allowNewMessagesFromUnfilteredChannels = true,
3536
) => {
3637
const { client } = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
3738

3839
useEffect(() => {
3940
const handleEvent = async (event: Event<At, Ch, Co, Ev, Me, Re, Us>) => {
40-
// if new message, put move channel up
41-
// get channel if not in state currently
4241
if (customHandler && typeof customHandler === 'function') {
4342
customHandler(setChannels, event);
44-
} else if (event.channel?.type) {
43+
} else if (allowNewMessagesFromUnfilteredChannels && event.channel?.type) {
4544
const channel = await getChannel(client, event.channel.type, event.channel.id);
46-
// move channel to starting position
4745
setChannels((channels) => uniqBy([channel, ...channels], 'cid'));
4846
}
4947

0 commit comments

Comments
 (0)