@@ -37,7 +37,10 @@ const Channel = (props) => {
3737 disableIfFrozenChannel = true ,
3838 disableKeyboardCompatibleView = false ,
3939 emojiData = emojiDataDefault ,
40+ EmptyStateIndicator = EmptyStateIndicatorDefault ,
4041 KeyboardCompatibleView = KeyboardCompatibleViewDefault ,
42+ LoadingErrorIndicator = LoadingErrorIndicatorDefault ,
43+ LoadingIndicator = LoadingIndicatorDefault ,
4144 } = props ;
4245
4346 const { client } = useContext ( ChatContext ) ;
@@ -74,7 +77,7 @@ const Channel = (props) => {
7477 const [ threadHasMore , setThreadHasMore ] = useState ( true ) ;
7578 const [ threadLoadingMore , setThreadLoadingMore ] = useState ( false ) ;
7679 const [ threadMessages , setThreadMessages ] = useState (
77- channel . state ?. threads ?. [ props . thread ?. id ] || [ ] ,
80+ channel ? .state ?. threads ?. [ props . thread ?. id ] || [ ] ,
7881 ) ;
7982 const [ typing , setTyping ] = useState ( Immutable ( { } ) ) ;
8083 const [ watcherCount , setWatcherCount ] = useState ( ) ;
@@ -85,7 +88,7 @@ const Channel = (props) => {
8588
8689 return ( ) => {
8790 client . off ( 'connection.recovered' , handleEvent ) ;
88- channel . off ?. ( handleEvent ) ;
91+ channel ? .off ?. ( handleEvent ) ;
8992 handleEventStateThrottled . cancel ( ) ;
9093 loadMoreFinishedDebounced . cancel ( ) ;
9194 loadMoreThreadFinishedDebounced . cancel ( ) ;
@@ -192,7 +195,7 @@ const Channel = (props) => {
192195 const initChannel = async ( ) => {
193196 let initError = false ;
194197
195- if ( ! channel . initialized ) {
198+ if ( ! channel . initialized && channel . cid ) {
196199 try {
197200 await channel . watch ( ) ;
198201 } catch ( e ) {
@@ -456,9 +459,8 @@ const Channel = (props) => {
456459
457460 const channelContext = {
458461 channel,
459- disabled : channel . data ?. frozen && disableIfFrozenChannel ,
460- EmptyStateIndicator :
461- props . EmptyStateIndicator || EmptyStateIndicatorDefault ,
462+ disabled : channel ?. data ?. frozen && disableIfFrozenChannel ,
463+ EmptyStateIndicator,
462464 error,
463465 eventHistory,
464466 lastRead,
@@ -500,6 +502,10 @@ const Channel = (props) => {
500502 threadMessages,
501503 } ;
502504
505+ if ( ! channel || error ) {
506+ return < LoadingErrorIndicator error = { error } listType = 'message' /> ;
507+ }
508+
503509 if ( ! channel ?. cid || ! channel . watch ) {
504510 return (
505511 < Text style = { { fontWeight : 'bold' , padding : 16 } } testID = 'no-channel' >
@@ -508,13 +514,7 @@ const Channel = (props) => {
508514 ) ;
509515 }
510516
511- if ( error ) {
512- const { LoadingErrorIndicator = LoadingErrorIndicatorDefault } = props ;
513- return < LoadingErrorIndicator error = { error } listType = 'message' /> ;
514- }
515-
516517 if ( loading ) {
517- const { LoadingIndicator = LoadingIndicatorDefault } = props ;
518518 return < LoadingIndicator listType = 'message' /> ;
519519 }
520520
0 commit comments