11import { useEffect } from 'react' ;
22
3- import uniqBy from 'lodash/uniqBy' ;
4-
53import type { Channel , Event } from 'stream-chat' ;
64
75import { 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' ;
1412import { isChannelArchived } from '../utils' ;
1513
1614type 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