File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
src/components/ChannelList/hooks Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 11// @ts -check
22
33import { useEffect , useContext } from 'react' ;
4+ import uniqBy from 'lodash.uniqby' ;
5+
46import { ChatContext } from '../../../context' ;
57import { moveChannelUp } from '../utils' ;
68
@@ -18,13 +20,18 @@ export const useMessageNewListener = (
1820 /** @param {import('stream-chat').Event } e */
1921 const handleEvent = ( e ) => {
2022 setChannels ( ( channels ) => {
23+ const channelInList =
24+ channels . filter ( ( c ) => c . cid === e . cid ) . length > 0 ;
25+ if ( ! channelInList ) {
26+ // @ts -ignore
27+ const channel = client . channel ( e . channel_type , e . channel_id ) ;
28+ return uniqBy ( [ channel , ...channels ] , 'cid' ) ;
29+ }
2130 if ( ! lockChannelOrder ) return moveChannelUp ( e . cid , channels ) ;
2231 return channels ;
2332 } ) ;
2433 } ;
25-
2634 client . on ( 'message.new' , handleEvent ) ;
27-
2835 return ( ) => {
2936 client . off ( 'message.new' , handleEvent ) ;
3037 } ;
You can’t perform that action at this time.
0 commit comments