@@ -644,6 +644,7 @@ const ChannelWithContext = <
644644 colors : { black } ,
645645 } ,
646646 } = useTheme ( ) ;
647+ const [ deleted , setDeleted ] = useState < boolean > ( false ) ;
647648 const [ editing , setEditing ] = useState < MessageType < StreamChatGenerics > | undefined > ( undefined ) ;
648649 const [ error , setError ] = useState < Error | boolean > ( false ) ;
649650 const [ lastRead , setLastRead ] = useState < ChannelContextValue < StreamChatGenerics > [ 'lastRead' ] > ( ) ;
@@ -777,11 +778,23 @@ const ChannelWithContext = <
777778 return ( ) => {
778779 copyChannelState . cancel ( ) ;
779780 loadMoreThreadFinished . cancel ( ) ;
780- listener . unsubscribe ( ) ;
781+ listener ? .unsubscribe ( ) ;
781782 } ;
782783 // eslint-disable-next-line react-hooks/exhaustive-deps
783784 } , [ channel . cid , messageId , shouldSyncChannel ] ) ;
784785
786+ // subscribe to channel.deleted event
787+ useEffect ( ( ) => {
788+ const { unsubscribe } = client . on ( 'channel.deleted' , ( event ) => {
789+ if ( event . cid === channel ?. cid ) {
790+ setDeleted ( true ) ;
791+ }
792+ } ) ;
793+
794+ return unsubscribe ;
795+ // eslint-disable-next-line react-hooks/exhaustive-deps
796+ } , [ channelId ] ) ;
797+
785798 /**
786799 * Subscription to the Notification mark_read event.
787800 */
@@ -1815,6 +1828,9 @@ const ChannelWithContext = <
18151828 typing : channelState . typing ?? { } ,
18161829 } ) ;
18171830
1831+ // TODO: replace the null view with appropriate message. Currently this is waiting a design decision.
1832+ if ( deleted ) return null ;
1833+
18181834 if ( ! channel || ( error && channelMessagesState . messages ?. length === 0 ) ) {
18191835 return < LoadingErrorIndicator error = { error } listType = 'message' retry = { reloadChannel } /> ;
18201836 }
0 commit comments