@@ -35,8 +35,8 @@ import { useCreateTypingContext } from './hooks/useCreateTypingContext';
3535import { useTargetedMessage } from './hooks/useTargetedMessage' ;
3636
3737import { ChannelContextValue , ChannelProvider } from '../../contexts/channelContext/ChannelContext' ;
38- import { useChannelState } from '../../contexts/channelsStateContext/useChannelState' ;
3938import type { UseChannelStateValue } from '../../contexts/channelsStateContext/useChannelState' ;
39+ import { useChannelState } from '../../contexts/channelsStateContext/useChannelState' ;
4040import { ChatContextValue , useChatContext } from '../../contexts/chatContext/ChatContext' ;
4141import {
4242 InputMessageInputContextValue ,
@@ -771,25 +771,29 @@ const ChannelWithContext = <
771771 const channelSubscriptions : Array < ReturnType < ChannelType [ 'on' ] > > = [ ] ;
772772 const clientSubscriptions : Array < ReturnType < StreamChat [ 'on' ] > > = [ ] ;
773773
774- const subscribe = ( ) => {
775- if ( ! channel ) return ;
774+ if ( ! channel ) return ;
776775
777- /**
778- * The more complex sync logic around internet connectivity (NetInfo) is part of Chat.tsx
779- * listen to client.connection.recovered and all channel events
780- */
776+ clientSubscriptions . push (
777+ client . on ( 'channel.deleted' , ( event ) => {
778+ if ( event . cid === channel . cid ) {
779+ setDeleted ( true ) ;
780+ }
781+ } ) ,
782+ ) ;
783+
784+ if ( enableOfflineSupport ) {
781785 clientSubscriptions . push ( DBSyncManager . onSyncStatusChange ( connectionChangedHandler ) ) ;
786+ } else {
782787 clientSubscriptions . push (
783- client . on ( 'channel.deleted ' , ( event ) => {
784- if ( event . cid === channel . cid ) {
785- setDeleted ( true ) ;
788+ client . on ( 'connection.changed ' , ( event ) => {
789+ if ( event . online ) {
790+ connectionChangedHandler ( ) ;
786791 }
787792 } ) ,
788793 ) ;
789- channelSubscriptions . push ( channel . on ( handleEvent ) ) ;
790- } ;
794+ }
791795
792- subscribe ( ) ;
796+ channelSubscriptions . push ( channel . on ( handleEvent ) ) ;
793797
794798 return ( ) => {
795799 clientSubscriptions . forEach ( ( s ) => s . unsubscribe ( ) ) ;
0 commit comments