File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
projects/stream-chat-angular/src/lib Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -1508,4 +1508,19 @@ describe('ChannelService', () => {
15081508 expect ( customFileDeleteRequest ) . toHaveBeenCalledWith ( url , channel ) ;
15091509 expect ( channel . deleteFile ) . not . toHaveBeenCalled ( ) ;
15101510 } ) ;
1511+
1512+ it ( 'should reset state after connection recovered' , async ( ) => {
1513+ await init ( ) ;
1514+ spyOn ( service , 'init' ) ;
1515+ spyOn ( service , 'reset' ) ;
1516+ events$ . next ( { eventType : 'connection.recovered' } as ClientEvent ) ;
1517+
1518+ expect ( service . init ) . toHaveBeenCalledWith (
1519+ service [ 'filters' ] ! ,
1520+ service [ 'sort' ] ,
1521+ service [ 'options' ] ,
1522+ service [ 'shouldSetActiveChannel' ]
1523+ ) ;
1524+ expect ( service . reset ) . toHaveBeenCalledWith ( ) ;
1525+ } ) ;
15111526} ) ;
Original file line number Diff line number Diff line change @@ -258,6 +258,7 @@ export class ChannelService<
258258 [ ]
259259 ) ;
260260 private _shouldMarkActiveChannelAsRead = true ;
261+ private shouldSetActiveChannel : boolean | undefined ;
261262
262263 private channelListSetter = (
263264 channels : ( Channel < T > | ChannelResponse < T > ) [ ]
@@ -486,7 +487,8 @@ export class ChannelService<
486487 message_limit : this . messagePageSize ,
487488 } ;
488489 this . sort = sort || { last_message_at : - 1 , updated_at : - 1 } ;
489- const result = await this . queryChannels ( shouldSetActiveChannel ) ;
490+ this . shouldSetActiveChannel = shouldSetActiveChannel ;
491+ const result = await this . queryChannels ( this . shouldSetActiveChannel ) ;
490492 this . chatClientService . events$ . subscribe (
491493 ( notification ) => void this . handleNotification ( notification )
492494 ) ;
@@ -790,6 +792,18 @@ export class ChannelService<
790792
791793 private handleNotification ( clientEvent : ClientEvent < T > ) {
792794 switch ( clientEvent . eventType ) {
795+ case 'connection.recovered' : {
796+ this . ngZone . run ( ( ) => {
797+ this . reset ( ) ;
798+ this . init (
799+ this . filters ! ,
800+ this . sort ,
801+ this . options ,
802+ this . shouldSetActiveChannel
803+ ) ;
804+ } ) ;
805+ break ;
806+ }
793807 case 'notification.message_new' : {
794808 this . ngZone . run ( ( ) => {
795809 if ( this . customNewMessageNotificationHandler ) {
You can’t perform that action at this time.
0 commit comments