@@ -73,9 +73,16 @@ const ChannelList = withChatContext(
7373 * Function that overrides default behaviour when channel gets updated
7474 *
7575 * @param {Component } thisArg Reference to ChannelList component
76- * @param {Event } event [Event object](https://getstream.io/chat/docs/#event_object) corresponding to `notification.channel_updated ` event
76+ * @param {Event } event [Event object](https://getstream.io/chat/docs/#event_object) corresponding to `channel.updated ` event
7777 * */
7878 onChannelUpdated : PropTypes . func ,
79+ /**
80+ * Function that overrides default behaviour when channel gets deleted. In absence of this prop, channel will be removed from the list.
81+ *
82+ * @param {Component } thisArg Reference to ChannelList component
83+ * @param {Event } event [Event object](https://getstream.io/chat/docs/#event_object) corresponding to `channel.deleted` event
84+ * */
85+ onChannelDeleted : PropTypes . func ,
7986 /**
8087 * Object containing query filters
8188 * @see See [Channel query documentation](https://getstream.io/chat/docs/#query_channels) for a list of available fields for filter.
@@ -371,7 +378,7 @@ const ChannelList = withChatContext(
371378 }
372379 }
373380
374- // // Channel data is updated
381+ // Channel data is updated
375382 if ( e . type === 'channel.updated' ) {
376383 const channels = this . state . channels ;
377384 const channelIndex = channels . findIndex (
@@ -388,6 +395,27 @@ const ChannelList = withChatContext(
388395 )
389396 this . props . onChannelUpdated ( this , e ) ;
390397 }
398+
399+ // Channel is deleted
400+ if ( e . type === 'channel.deleted' ) {
401+ if (
402+ this . props . onChannelDeleted &&
403+ typeof this . props . onChannelDeleted === 'function'
404+ ) {
405+ this . props . onChannelDeleted ( this , e ) ;
406+ } else {
407+ const channels = this . state . channels ;
408+ const channelIndex = channels . findIndex (
409+ ( channel ) => channel . cid === e . channel . cid ,
410+ ) ;
411+ // Remove the deleted channel from the list.
412+ channels . splice ( channelIndex , 1 ) ;
413+ this . setState ( {
414+ channels : [ ...channels ] ,
415+ } ) ;
416+ }
417+ }
418+
391419 return null ;
392420 } ;
393421
0 commit comments