Skip to content

Commit 32f48ee

Browse files
committed
fix: notification.message_new not respecting pinning as well
1 parent 0f2a0f9 commit 32f48ee

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

package/src/components/ChannelList/hooks/listeners/useNewMessageNotification.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { useEffect } from 'react';
22

3-
import uniqBy from 'lodash/uniqBy';
4-
53
import type { Channel, Event } from 'stream-chat';
64

75
import { useChatContext } from '../../../../contexts/chatContext/ChatContext';
@@ -10,7 +8,7 @@ import type {
108
ChannelListEventListenerOptions,
119
DefaultStreamChatGenerics,
1210
} from '../../../../types/types';
13-
import { getChannel } from '../../utils';
11+
import { getChannel, moveChannelUp } from '../../utils';
1412
import { isChannelArchived } from '../utils';
1513

1614
type Parameters<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> =
@@ -39,7 +37,7 @@ export const useNewMessageNotification = <
3937
onNewMessageNotification(setChannels, event, options);
4038
} else {
4139
if (!options) return;
42-
const { filters } = options;
40+
const { filters, sort } = options;
4341
if (event.channel?.id && event.channel?.type) {
4442
const channel = await getChannel({
4543
client,
@@ -53,7 +51,16 @@ export const useNewMessageNotification = <
5351
return;
5452
}
5553

56-
setChannels((channels) => (channels ? uniqBy([channel, ...channels], 'cid') : channels));
54+
setChannels((channels) =>
55+
channels
56+
? moveChannelUp({
57+
channels,
58+
channelToMove: channel,
59+
channelToMoveIndexWithinChannels: -1,
60+
sort,
61+
})
62+
: channels,
63+
);
5764
}
5865
}
5966
};

0 commit comments

Comments
 (0)