@@ -76,6 +76,13 @@ const ChannelList = withChatContext(
7676 * @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 to customize behaviour when channel gets truncated
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.truncated` event
84+ * */
85+ onChannelTruncated : PropTypes . func ,
7986 /**
8087 * Function that overrides default behaviour when channel gets deleted. In absence of this prop, channel will be removed from the list.
8188 *
@@ -108,6 +115,10 @@ const ChannelList = withChatContext(
108115 * @param channel A Channel object
109116 */
110117 setActiveChannel : PropTypes . func ,
118+ /**
119+ * If true, channels won't be dynamically sorted by most recent message.
120+ */
121+ lockChannelOrder : PropTypes . bool ,
111122 } ;
112123
113124 static defaultProps = {
@@ -121,6 +132,7 @@ const ChannelList = withChatContext(
121132 sort : { } ,
122133 // https://github.com/facebook/react-native/blob/a7a7970e543959e9db5281914d5f132beb01db8d/Libraries/Lists/VirtualizedList.js#L466
123134 loadMoreThreshold : 2 ,
135+ lockChannelOrder : false ,
124136 logger : ( ) => { } ,
125137 } ;
126138
@@ -301,7 +313,7 @@ const ChannelList = withChatContext(
301313 }
302314
303315 if ( e . type === 'message.new' ) {
304- this . moveChannelUp ( e . cid ) ;
316+ ! this . props . lockChannelOrder && this . moveChannelUp ( e . cid ) ;
305317 }
306318
307319 // make sure to re-render the channel list after connection is recovered
@@ -416,6 +428,18 @@ const ChannelList = withChatContext(
416428 }
417429 }
418430
431+ if ( e . type === 'channel.truncated' ) {
432+ this . setState ( ( prevState ) => ( {
433+ channels : [ ...prevState . channels ] ,
434+ } ) ) ;
435+
436+ if (
437+ this . props . onChannelTruncated &&
438+ typeof this . props . onChannelTruncated === 'function'
439+ )
440+ this . props . onChannelTruncated ( this , e ) ;
441+ }
442+
419443 return null ;
420444 } ;
421445
0 commit comments