@@ -65,6 +65,7 @@ import { useTranslationContext } from '../../context/TranslationContext';
6565import { TypingProvider } from '../../context/TypingContext' ;
6666
6767import {
68+ DEFAULT_HIGHLIGHT_DURATION ,
6869 DEFAULT_INITIAL_CHANNEL_PAGE_SIZE ,
6970 DEFAULT_JUMP_TO_PAGE_SIZE ,
7071 DEFAULT_NEXT_CHANNEL_PAGE_SIZE ,
@@ -753,46 +754,58 @@ const ChannelInner = <
753754
754755 const clearHighlightedMessageTimeoutId = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
755756
756- const jumpToMessage = async ( messageId : string , messageLimit = DEFAULT_JUMP_TO_PAGE_SIZE ) => {
757- dispatch ( { loadingMore : true , type : 'setLoadingMore' } ) ;
758- await channel . state . loadMessageIntoState ( messageId , undefined , messageLimit ) ;
757+ const jumpToMessage = useCallback (
758+ async (
759+ messageId : string ,
760+ messageLimit = DEFAULT_JUMP_TO_PAGE_SIZE ,
761+ highlightDuration = DEFAULT_HIGHLIGHT_DURATION ,
762+ ) => {
763+ dispatch ( { loadingMore : true , type : 'setLoadingMore' } ) ;
764+ await channel . state . loadMessageIntoState ( messageId , undefined , messageLimit ) ;
759765
760- /**
761- * if the message we are jumping to has less than half of the page size older messages,
762- * we have jumped to the beginning of the channel.
763- */
764- const indexOfMessage = channel . state . messages . findIndex ( ( message ) => message . id === messageId ) ;
765- const hasMoreMessages = indexOfMessage >= Math . floor ( messageLimit / 2 ) ;
766+ /**
767+ * if the message we are jumping to has less than half of the page size older messages,
768+ * we have jumped to the beginning of the channel.
769+ */
770+ const indexOfMessage = channel . state . messages . findIndex (
771+ ( message ) => message . id === messageId ,
772+ ) ;
773+ const hasMoreMessages = indexOfMessage >= Math . floor ( messageLimit / 2 ) ;
766774
767- loadMoreFinished ( hasMoreMessages , channel . state . messages ) ;
768- dispatch ( {
769- hasMoreNewer : channel . state . messages !== channel . state . latestMessages ,
770- highlightedMessageId : messageId ,
771- type : 'jumpToMessageFinished' ,
772- } ) ;
775+ loadMoreFinished ( hasMoreMessages , channel . state . messages ) ;
776+ dispatch ( {
777+ hasMoreNewer : channel . state . messages !== channel . state . latestMessages ,
778+ highlightedMessageId : messageId ,
779+ type : 'jumpToMessageFinished' ,
780+ } ) ;
773781
774- if ( clearHighlightedMessageTimeoutId . current ) {
775- clearTimeout ( clearHighlightedMessageTimeoutId . current ) ;
776- }
782+ if ( clearHighlightedMessageTimeoutId . current ) {
783+ clearTimeout ( clearHighlightedMessageTimeoutId . current ) ;
784+ }
777785
778- clearHighlightedMessageTimeoutId . current = setTimeout ( ( ) => {
779- clearHighlightedMessageTimeoutId . current = null ;
780- dispatch ( { type : 'clearHighlightedMessage' } ) ;
781- } , 500 ) ;
782- } ;
786+ clearHighlightedMessageTimeoutId . current = setTimeout ( ( ) => {
787+ clearHighlightedMessageTimeoutId . current = null ;
788+ dispatch ( { type : 'clearHighlightedMessage' } ) ;
789+ } , highlightDuration ) ;
790+ } ,
791+ [ channel , loadMoreFinished ] ,
792+ ) ;
783793
784- const jumpToLatestMessage = async ( ) => {
794+ const jumpToLatestMessage = useCallback ( async ( ) => {
785795 await channel . state . loadMessageIntoState ( 'latest' ) ;
786796 // FIXME: we cannot rely on constant value 25 as the page size can be customized by integrators
787797 const hasMoreOlder = channel . state . messages . length >= 25 ;
788798 loadMoreFinished ( hasMoreOlder , channel . state . messages ) ;
789799 dispatch ( {
790800 type : 'jumpToLatestMessage' ,
791801 } ) ;
792- } ;
802+ } , [ channel , loadMoreFinished ] ) ;
793803
794804 const jumpToFirstUnreadMessage = useCallback (
795- async ( queryMessageLimit = DEFAULT_JUMP_TO_PAGE_SIZE ) => {
805+ async (
806+ queryMessageLimit = DEFAULT_JUMP_TO_PAGE_SIZE ,
807+ highlightDuration = DEFAULT_HIGHLIGHT_DURATION ,
808+ ) => {
796809 if ( ! channelUnreadUiState ?. unread_messages ) return ;
797810 let lastReadMessageId = channelUnreadUiState ?. last_read_message_id ;
798811 let firstUnreadMessageId = channelUnreadUiState ?. first_unread_message_id ;
@@ -914,7 +927,7 @@ const ChannelInner = <
914927 clearHighlightedMessageTimeoutId . current = setTimeout ( ( ) => {
915928 clearHighlightedMessageTimeoutId . current = null ;
916929 dispatch ( { type : 'clearHighlightedMessage' } ) ;
917- } , 500 ) ;
930+ } , highlightDuration ) ;
918931 } ,
919932 [ addNotification , channel , loadMoreFinished , t , channelUnreadUiState ] ,
920933 ) ;
0 commit comments