@@ -13,23 +13,6 @@ import React, {
1313import debounce from 'lodash.debounce' ;
1414import defaultsDeep from 'lodash.defaultsdeep' ;
1515import throttle from 'lodash.throttle' ;
16- import {
17- APIErrorResponse ,
18- ChannelAPIResponse ,
19- ChannelMemberResponse ,
20- ChannelQueryOptions ,
21- ChannelState ,
22- ErrorFromResponse ,
23- Event ,
24- EventAPIResponse ,
25- Message ,
26- MessageResponse ,
27- SendMessageAPIResponse ,
28- Channel as StreamChannel ,
29- StreamChat ,
30- UpdatedMessage ,
31- UserResponse ,
32- } from 'stream-chat' ;
3316import { nanoid } from 'nanoid' ;
3417import clsx from 'clsx' ;
3518
@@ -62,6 +45,7 @@ import {
6245 WithComponents ,
6346} from '../../context' ;
6447
48+ import { CHANNEL_CONTAINER_ID } from './constants' ;
6549import {
6650 DEFAULT_HIGHLIGHT_DURATION ,
6751 DEFAULT_INITIAL_CHANNEL_PAGE_SIZE ,
@@ -77,10 +61,27 @@ import {
7761 useImageFlagEmojisOnWindowsClass ,
7862} from './hooks/useChannelContainerClasses' ;
7963import { findInMsgSetByDate , findInMsgSetById , makeAddNotifications } from './utils' ;
64+ import { useThreadContext } from '../Threads' ;
8065import { getChannel } from '../../utils' ;
8166
67+ import type {
68+ APIErrorResponse ,
69+ ChannelAPIResponse ,
70+ ChannelMemberResponse ,
71+ ChannelQueryOptions ,
72+ ChannelState ,
73+ ErrorFromResponse ,
74+ Event ,
75+ EventAPIResponse ,
76+ Message ,
77+ MessageResponse ,
78+ SendMessageAPIResponse ,
79+ Channel as StreamChannel ,
80+ StreamChat ,
81+ UpdatedMessage ,
82+ UserResponse ,
83+ } from 'stream-chat' ;
8284import type { MessageInputProps } from '../MessageInput' ;
83-
8485import type {
8586 ChannelUnreadUiState ,
8687 CustomTrigger ,
@@ -96,8 +97,7 @@ import {
9697 getVideoAttachmentConfiguration ,
9798} from '../Attachment/attachment-sizing' ;
9899import type { URLEnrichmentConfig } from '../MessageInput/hooks/useLinkPreviews' ;
99- import { useThreadContext } from '../Threads' ;
100- import { CHANNEL_CONTAINER_ID } from './constants' ;
100+ import { useSearchFocusedMessage } from '../../experimental/Search/hooks' ;
101101
102102type ChannelPropsForwardedToComponentContext <
103103 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
@@ -360,7 +360,7 @@ const ChannelInner = <
360360 [ propChannelQueryOptions ] ,
361361 ) ;
362362
363- const { client, customClasses, latestMessageDatesByChannels, mutes } =
363+ const { client, customClasses, latestMessageDatesByChannels, mutes, searchController } =
364364 useChatContext < StreamChatGenerics > ( 'Channel' ) ;
365365 const { t } = useTranslationContext ( 'Channel' ) ;
366366 const chatContainerClass = getChatContainerClass ( customClasses ?. chatContainer ) ;
@@ -387,13 +387,17 @@ const ChannelInner = <
387387 loading : ! channel . initialized ,
388388 } ,
389389 ) ;
390-
390+ const jumpToMessageFromSearch = useSearchFocusedMessage ( ) ;
391391 const isMounted = useIsMounted ( ) ;
392392
393393 const originalTitle = useRef ( '' ) ;
394394 const lastRead = useRef < Date | undefined > ( undefined ) ;
395395 const online = useRef ( true ) ;
396396
397+ const clearHighlightedMessageTimeoutId = useRef < ReturnType < typeof setTimeout > | null > (
398+ null ,
399+ ) ;
400+
397401 const channelCapabilitiesArray = channel . data ?. own_capabilities as string [ ] ;
398402
399403 const throttledCopyStateFromChannel = throttle (
@@ -647,6 +651,38 @@ const ChannelInner = <
647651 if ( message ) dispatch ( { message, type : 'setThread' } ) ;
648652 } , [ state . messages , state . thread ] ) ;
649653
654+ const handleHighlightedMessageChange = useCallback (
655+ ( {
656+ highlightDuration,
657+ highlightedMessageId,
658+ } : {
659+ highlightedMessageId : string ;
660+ highlightDuration ?: number ;
661+ } ) => {
662+ dispatch ( {
663+ channel,
664+ highlightedMessageId,
665+ type : 'jumpToMessageFinished' ,
666+ } ) ;
667+ if ( clearHighlightedMessageTimeoutId . current ) {
668+ clearTimeout ( clearHighlightedMessageTimeoutId . current ) ;
669+ }
670+ clearHighlightedMessageTimeoutId . current = setTimeout ( ( ) => {
671+ if ( searchController . _internalState . getLatestValue ( ) . focusedMessage ) {
672+ searchController . _internalState . partialNext ( { focusedMessage : undefined } ) ;
673+ }
674+ clearHighlightedMessageTimeoutId . current = null ;
675+ dispatch ( { type : 'clearHighlightedMessage' } ) ;
676+ } , highlightDuration ?? DEFAULT_HIGHLIGHT_DURATION ) ;
677+ } ,
678+ [ channel , searchController ] ,
679+ ) ;
680+
681+ useEffect ( ( ) => {
682+ if ( ! jumpToMessageFromSearch ?. id ) return ;
683+ handleHighlightedMessageChange ( { highlightedMessageId : jumpToMessageFromSearch . id } ) ;
684+ } , [ jumpToMessageFromSearch , handleHighlightedMessageChange ] ) ;
685+
650686 /** MESSAGE */
651687
652688 // Adds a temporary notification to message list, will be removed after 5 seconds
@@ -745,10 +781,6 @@ const ChannelInner = <
745781 return queryResponse . messages . length ;
746782 } ;
747783
748- const clearHighlightedMessageTimeoutId = useRef < ReturnType < typeof setTimeout > | null > (
749- null ,
750- ) ;
751-
752784 const jumpToMessage : ChannelActionContextValue < StreamChatGenerics > [ 'jumpToMessage' ] =
753785 useCallback (
754786 async (
@@ -760,22 +792,12 @@ const ChannelInner = <
760792 await channel . state . loadMessageIntoState ( messageId , undefined , messageLimit ) ;
761793
762794 loadMoreFinished ( channel . state . messagePagination . hasPrev , channel . state . messages ) ;
763- dispatch ( {
764- hasMoreNewer : channel . state . messagePagination . hasNext ,
795+ handleHighlightedMessageChange ( {
796+ highlightDuration ,
765797 highlightedMessageId : messageId ,
766- type : 'jumpToMessageFinished' ,
767798 } ) ;
768-
769- if ( clearHighlightedMessageTimeoutId . current ) {
770- clearTimeout ( clearHighlightedMessageTimeoutId . current ) ;
771- }
772-
773- clearHighlightedMessageTimeoutId . current = setTimeout ( ( ) => {
774- clearHighlightedMessageTimeoutId . current = null ;
775- dispatch ( { type : 'clearHighlightedMessage' } ) ;
776- } , highlightDuration ) ;
777799 } ,
778- [ channel , loadMoreFinished ] ,
800+ [ channel , handleHighlightedMessageChange , loadMoreFinished ] ,
779801 ) ;
780802
781803 const jumpToLatestMessage : ChannelActionContextValue < StreamChatGenerics > [ 'jumpToLatestMessage' ] =
@@ -916,23 +938,19 @@ const ChannelInner = <
916938 first_unread_message_id : firstUnreadMessageId ,
917939 last_read_message_id : lastReadMessageId ,
918940 } ) ;
919-
920- dispatch ( {
921- hasMoreNewer : channel . state . messagePagination . hasNext ,
941+ handleHighlightedMessageChange ( {
942+ highlightDuration,
922943 highlightedMessageId : firstUnreadMessageId ,
923- type : 'jumpToMessageFinished' ,
924944 } ) ;
925-
926- if ( clearHighlightedMessageTimeoutId . current ) {
927- clearTimeout ( clearHighlightedMessageTimeoutId . current ) ;
928- }
929-
930- clearHighlightedMessageTimeoutId . current = setTimeout ( ( ) => {
931- clearHighlightedMessageTimeoutId . current = null ;
932- dispatch ( { type : 'clearHighlightedMessage' } ) ;
933- } , highlightDuration ) ;
934945 } ,
935- [ addNotification , channel , loadMoreFinished , t , channelUnreadUiState ] ,
946+ [
947+ addNotification ,
948+ channel ,
949+ handleHighlightedMessageChange ,
950+ loadMoreFinished ,
951+ t ,
952+ channelUnreadUiState ,
953+ ] ,
936954 ) ;
937955
938956 const deleteMessage = useCallback (
0 commit comments