Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(chat): add message search (#17644)
Alok-work233f4bd6ce6fd5
diff --git a/lang/main.json b/lang/main.jsonindex 166c113324..cfef35b466 100644--- a/lang/main.json+++ b/lang/main.json@@ -149,6 +149,15 @@},"noMessagesMessage": "There are no messages in the meeting yet. Start a conversation here!","privateNotice": "Private message to {{recipient}}",+ "search": {+ "close": "Close search",+ "next": "Next match",+ "noResults": "No results",+ "open": "Search messages",+ "placeholder": "Search in chat",+ "previous": "Previous match",+ "resultsCount": "{{current}}/{{total}}"+ },"sendButton": "Send","smileysPanel": "Emoji panel","systemDisplayName": "System",diff --git a/package-lock.json b/package-lock.jsonindex fc9cec2882..2d78d9664e 100644--- a/package-lock.json+++ b/package-lock.json@@ -118,6 +118,7 @@"react-youtube": "10.1.0","redux": "4.0.4","redux-thunk": "2.4.1",+ "reselect": "5.2.0","seamless-scroll-polyfill": "2.1.8","semver": "7.5.4","text-encoding": "0.7.0",@@ -24178,6 +24179,12 @@"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=","dev": true},+ "node_modules/reselect": {+ "version": "5.2.0",+ "resolved": "https://registry.npmjs.org/reselect/-/reselect-5.2.0.tgz",+ "integrity": "sha512-AgZ3UOZm3YndfrJ4OYjgrT7bmCm/1iqkjvEfH/oYjzh6PD2qw4QuT3jjnXIrpdt4MTpMXclMT3lXbmRY+XRakw==",+ "license": "MIT"+ },"node_modules/resize-observer-polyfill": {"version": "1.5.1","resolved": "https://registry.npmjs.org/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz",@@ -44278,6 +44285,11 @@"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=","dev": true},+ "reselect": {+ "version": "5.2.0",+ "resolved": "https://registry.npmjs.org/reselect/-/reselect-5.2.0.tgz",+ "integrity": "sha512-AgZ3UOZm3YndfrJ4OYjgrT7bmCm/1iqkjvEfH/oYjzh6PD2qw4QuT3jjnXIrpdt4MTpMXclMT3lXbmRY+XRakw=="+ },"resize-observer-polyfill": {"version": "1.5.1","resolved": "https://registry.npmjs.org/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz",diff --git a/package.json b/package.jsonindex 55f67c2ead..e2bda78f63 100644--- a/package.json+++ b/package.json@@ -124,6 +124,7 @@"react-youtube": "10.1.0","redux": "4.0.4","redux-thunk": "2.4.1",+ "reselect": "5.2.0","seamless-scroll-polyfill": "2.1.8","semver": "7.5.4","text-encoding": "0.7.0",diff --git a/react/features/base/react/components/web/Message.tsx b/react/features/base/react/components/web/Message.tsxindex c4235f21f0..89c247b2db 100644--- a/react/features/base/react/components/web/Message.tsx+++ b/react/features/base/react/components/web/Message.tsx@@ -15,6 +15,12 @@ interface IProps {*/gifEnabled: boolean;+ /**+ * Case-insensitive search query whose matches should be wrapped in <mark>.+ * Left undefined/empty for no highlighting.+ */+ highlightQuery?: string;+/*** Message decoration for screen reader.*/@@ -43,13 +49,63 @@ class Message extends Component<IProps> {this._processMessage = this._processMessage.bind(this);}+ /**+ * Wraps case-insensitive matches of query inside token in <mark>. Intended for plain-text+ * tokens only — callers must skip URL/mention tokens so links stay intact.+ *+ * @param {string} token - The text to search within.+ * @param {string} query - The search query.+ * @returns {Array<string | ReactNode>}+ */+ _highlightMatches(token: string, query: string) {+ const lowerToken = token.toLowerCase();+ const lowerQuery = query.toLowerCase();++ if (!lowerQuery || !lowerToken.includes(lowerQuery)) {+ return [ token ];+ }++ const parts: (string | ReactNode)[] = [];+ let remaining = token;+ let remainingLower = lowerToken;+ let offset = 0;++ // eslint-disable-next-line no-constant-condition+ while (true) {+ const matchIndex = remainingLower.indexOf(lowerQuery);++ if (matchIndex === -1) {+ parts.push(remaining);+ break;+ }++ if (matchIndex > 0) {+ parts.push(remaining.slice(0, matchIndex));+ }++ const matchEnd = matchIndex + lowerQuery.length;++ parts.push(+ <mark key = { `match-${offset}` }>+ { remaining.slice(matchIndex, matchEnd) }+ </mark>+ );++ remaining = remaining.slice(matchEnd);+ remainingLower = remainingLower.slice(matchEnd);+ offset += matchEnd;+ }++ return parts;+ }+/*** Parses and builds the message tokens to include emojis and urls.** @returns {Array<string|ReactElement>}*/_processMessage() {- const { text } = this.props;+ const { text, highlightQuery } = this.props;const message: (string | ReactNode)[] = [];// Tokenize the text in order to avoid emoji substitution for URLs@@ -85,7 +141,12 @@ class Message extends Component<IProps> {content.forEach((token, index) => {if (typeof token === 'string' && token !== ' ') {- message.push(<Linkify key = { `${token}-${index}` }>{ token }</Linkify>);+ const isLinkOrMention = token.includes('://') || token.startsWith('@');+ const children = (highlightQuery && !isLinkOrMention)+ ? this._highlightMatches(token, highlightQuery)+ : token;++ message.push(<Linkify key = { `${token}-${index}` }>{ children }</Linkify>);} else {message.push(token);}diff --git a/react/features/base/ui/components/native/Input.tsx b/react/features/base/ui/components/native/Input.tsxindex 10445e0b7f..84f9f11017 100644--- a/react/features/base/ui/components/native/Input.tsx+++ b/react/features/base/ui/components/native/Input.tsx@@ -56,6 +56,7 @@ interface IProps extends IInputProps {}interface ICustomStyles {+ clearButton?: Object;container?: Object;input?: Object;}@@ -172,7 +173,7 @@ const Input = forwardRef<TextInput, IProps>(({{ clearable && !disabled && value !== '' && (<TouchableOpacityonPress = { clearInput }- style = { styles.clearButton as StyleProp<ViewStyle> }>+ style = { [ styles.clearButton, customStyles?.clearButton ] as StyleProp<ViewStyle> }><Iconsize = { 22 }src = { IconCloseCircle }diff --git a/react/features/base/ui/components/web/Input.tsx b/react/features/base/ui/components/web/Input.tsxindex e9a8841b59..fc065629dc 100644--- a/react/features/base/ui/components/web/Input.tsx+++ b/react/features/base/ui/components/web/Input.tsx@@ -26,6 +26,14 @@ interface IProps extends IInputProps {* info (label, error) so that screen reader users don't get lost.*/id: string;++ /**+ * Optional class name applied to the actual input/textarea element (as opposed to+ * `className`, which applies to the outer wrapping container). Useful for callers+ * that render Input inside their own bordered container and need to strip Input's+ * own background/border so only one visual box shows.+ */+ inputClassName?: string;invalidReason?: 'grammar' | 'spelling' | boolean;maxLength?: number;maxRows?: number;@@ -174,6 +182,7 @@ const Input = React.forwardRef<any, IProps>(({iconClick,id,invalidReason,+ inputClassName,label,maxValue,maxLength,@@ -256,7 +265,7 @@ const Input = React.forwardRef<any, IProps>(({autoComplete = { autoComplete }autoFocus = { autoFocus }className = { cx(styles.input, isMobile && 'is-mobile',- error && 'error', showClearIcon && 'clearable-input', icon && 'icon-input') }+ error && 'error', showClearIcon && 'clearable-input', icon && 'icon-input', inputClassName) }disabled = { disabled }id = { id }maxLength = { maxLength }@@ -278,7 +287,7 @@ const Input = React.forwardRef<any, IProps>(({autoComplete = { autoComplete }autoFocus = { autoFocus }className = { cx(styles.input, isMobile && 'is-mobile',- error && 'error', showClearIcon && 'clearable-input', icon && 'icon-input') }+ error && 'error', showClearIcon && 'clearable-input', icon && 'icon-input', inputClassName) }data-testid = { testId }disabled = { disabled }id = { id }diff --git a/react/features/chat/actionTypes.ts b/react/features/chat/actionTypes.tsindex 3bc8cb601f..6876976740 100644--- a/react/features/chat/actionTypes.ts+++ b/react/features/chat/actionTypes.ts@@ -25,6 +25,15 @@ export const ADD_MESSAGE = 'ADD_MESSAGE';*/export const ADD_MESSAGE_REACTION = 'ADD_MESSAGE_REACTION';+/**+ * The type of action which clears the chat search state.+ *+ * {+ * type: CLEAR_CHAT_SEARCH+ * }+ */+export const CLEAR_CHAT_SEARCH = 'CLEAR_CHAT_SEARCH';+/*** The type of the action which signals to clear Redux.*@@ -86,6 +95,26 @@ export const SEND_MESSAGE = 'SEND_MESSAGE';*/export const SEND_REACTION = 'SEND_REACTION';+/**+ * The type of action which sets the currently focused search match index.+ *+ * {+ * type: SET_CHAT_SEARCH_MATCH_INDEX,+ * index: number+ * }+ */+export const SET_CHAT_SEARCH_MATCH_INDEX = 'SET_CHAT_SEARCH_MATCH_INDEX';++/**+ * The type of action which sets the chat search query.+ *+ * {+ * type: SET_CHAT_SEARCH_QUERY,+ * query: string+ * }+ */+export const SET_CHAT_SEARCH_QUERY = 'SET_CHAT_SEARCH_QUERY';+/*** The type of action which signals the initiation of sending of as private message to the* supplied recipient.diff --git a/react/features/chat/actions.any.ts b/react/features/chat/actions.any.tsindex 5b8800d8c6..dfc5be5e93 100644--- a/react/features/chat/actions.any.ts+++ b/react/features/chat/actions.any.ts@@ -7,6 +7,7 @@ import { LOBBY_CHAT_INITIALIZED } from '../lobby/constants';import {ADD_MESSAGE,ADD_MESSAGE_REACTION,+ CLEAR_CHAT_SEARCH,CLEAR_CHAT_STATE,CLOSE_CHAT,EDIT_MESSAGE,@@ -15,6 +16,8 @@ import {REMOVE_LOBBY_CHAT_PARTICIPANT,SEND_MESSAGE,SEND_REACTION,+ SET_CHAT_SEARCH_MATCH_INDEX,+ SET_CHAT_SEARCH_QUERY,SET_FOCUSED_TAB,SET_LOBBY_CHAT_ACTIVE_STATE,SET_LOBBY_CHAT_RECIPIENT,@@ -92,6 +95,19 @@ export function editMessage(message: Object) {};}+/**+ * Clears the chat search query and match index.+ *+ * @returns {{+ * type: CLEAR_CHAT_SEARCH+ * }}+ */+export function clearChatSearch() {+ return {+ type: CLEAR_CHAT_SEARCH+ };+}+/*** Clears the chat features state from Redux.*@@ -155,6 +171,38 @@ export function sendReaction(reaction: string, messageId: string, receiverId?: s};}+/**+ * Sets the chat search query and resets the match index back to the first result.+ *+ * @param {string} query - The search text.+ * @returns {{+ * type: SET_CHAT_SEARCH_QUERY,+ * query: string+ * }}+ */+export function setChatSearchQuery(query: string) {+ return {+ type: SET_CHAT_SEARCH_QUERY,+ query+ };+}++/**+ * Sets which search match is currently focused (for prev/next navigation).+ *+ * @param {number} index - The index into the matches array.+ * @returns {{+ * type: SET_CHAT_SEARCH_MATCH_INDEX,+ * index: number+ * }}+ */+export function setChatSearchMatchIndex(index: number) {+ return {+ type: SET_CHAT_SEARCH_MATCH_INDEX,+ index+ };+}+/*** Initiates the sending of a private message to the supplied participant.*diff --git a/react/features/chat/components/native/Chat.tsx b/react/features/chat/components/native/Chat.tsxindex 5790f8900f..a41e93d088 100644--- a/react/features/chat/components/native/Chat.tsx+++ b/react/features/chat/components/native/Chat.tsx@@ -9,11 +9,12 @@ import JitsiScreen from '../../../base/modal/components/JitsiScreen';import { StyleType } from '../../../base/styles/functions.native';import { TabBarLabelCounter } from '../../../mobile/navigation/components/TabBarLabelCounter';import { pollsStyles } from '../../../polls/components/native/styles';-import { closeChat, sendMessage } from '../../actions.native';+import { clearChatSearch, closeChat, sendMessage } from '../../actions.native';import { ChatTabs } from '../../constants';import { IChatProps as AbstractProps } from '../../types';import ChatInputBar from './ChatInputBar';+import ChatSearchBar from './ChatSearchBar';import MessageContainer from './MessageContainer';import MessageRecipient from './MessageRecipient';@@ -71,6 +72,7 @@ class Chat extends Component<IProps> {hasBottomTextInput = { true }hasExtraHeaderHeight = { true }style = { pollsStyles.pollPaneContainer as StyleType }>+ <ChatSearchBar />{/* @ts-ignore */}<MessageContainer messages = { _messages } /><MessageRecipient privateMessageRecipient = { privateMessageRecipient } />@@ -143,7 +145,10 @@ export default translate(connect(_mapStateToProps)((props: IProps) => {});return () => {- isFocused && dispatch(closeChat());+ if (isFocused) {+ dispatch(closeChat());+ dispatch(clearChatSearch());+ }};}, [ isFocused, _unreadMessagesCount ]);diff --git a/react/features/chat/components/native/ChatMessage.tsx b/react/features/chat/components/native/ChatMessage.tsxindex c0addb1dc8..4e8544874d 100644--- a/react/features/chat/components/native/ChatMessage.tsx+++ b/react/features/chat/components/native/ChatMessage.tsx@@ -9,9 +9,12 @@ import Linkify from '../../../base/react/components/native/Linkify';import { isGifEnabled, isGifMessage } from '../../../gifs/functions.native';import { CHAR_LIMIT, MESSAGE_TYPE_ERROR, MESSAGE_TYPE_LOCAL } from '../../constants';import {+ getActiveChatSearchMatch,getCanReplyToMessage,+ getChatSearchQuery,getDisplayNameSuffix,getFormattedTimestamp,+ getHighlightSegments,getMessageText,getPrivateNoticeMessage,replaceNonUnicodeEmojis@@ -33,7 +36,7 @@ class ChatMessage extends Component<IChatMessageProps> {* @inheritdoc*/override render() {- const { gifEnabled, message, knocking } = this.props;+ const { gifEnabled, message, knocking, isActiveMatch } = this.props;const localMessage = message.messageType === MESSAGE_TYPE_LOCAL;const { privateMessage, lobbyChat } = message;@@ -74,6 +77,10 @@ class ChatMessage extends Component<IChatMessageProps> {messageBubbleStyle.push(styles.lobbyMessageBubble);}+ if (isActiveMatch) {+ messageBubbleStyle.push(styles.activeMatchMessageBubble);+ }+const messageText = getMessageText(this.props.message);return (@@ -145,8 +152,19 @@ class ChatMessage extends Component<IChatMessageProps> {* @returns {React.ReactElement<*>}*/_renderMessageTextComponent(messageText: string) {+ const { highlightQuery, isActiveMatch } = this.props;if (messageText.length >= CHAR_LIMIT) {+ if (highlightQuery && !isActiveMatch) {+ return (+ <Text+ selectable = { true }+ style = { styles.chatMessage }>+ { this._renderHighlightedSegments(messageText, highlightQuery, isActiveMatch) }+ </Text>+ );+ }+return (<Textselectable = { true }@@ -156,15 +174,39 @@ class ChatMessage extends Component<IChatMessageProps> {);}+ const processedText = replaceNonUnicodeEmojis(messageText);+return (<LinkifylinkStyle = { styles.chatLink }style = { styles.chatMessage }>- { replaceNonUnicodeEmojis(messageText) }+ { highlightQuery && !isActiveMatch+ ? this._renderHighlightedSegments(processedText, highlightQuery, isActiveMatch)+ : processedText }</Linkify>);}+ /**+ * Splits text into highlight/non-highlight segments and renders them.+ *+ * @param {string} text - The text to split.+ * @param {string} query - The active search query.+ * @param {boolean} [isActiveMatch] - Whether this message is the focused match.+ * @returns {Array<React.ReactNode>}+ */+ _renderHighlightedSegments(text: string, query: string, isActiveMatch?: boolean) {+ return getHighlightSegments(text, query).map((segment, index) => segment.match+ ? (+ <Text+ key = { index }+ style = { isActiveMatch ? styles.chatMessageHighlightActive : styles.chatMessageHighlight }>+ { segment.text }+ </Text>+ )+ : segment.text);+ }+/*** Renders the message privacy notice, if necessary.*@@ -235,9 +277,13 @@ class ChatMessage extends Component<IChatMessageProps> {* @returns {IProps}*/function _mapStateToProps(state: IReduxState, { message }: IChatMessageProps) {+ const activeMatch = getActiveChatSearchMatch(state);+return {canReply: getCanReplyToMessage(state, message),gifEnabled: isGifEnabled(state),+ highlightQuery: getChatSearchQuery(state),+ isActiveMatch: Boolean(activeMatch && activeMatch.messageId === message.messageId),knocking: state['features/lobby'].knocking};}diff --git a/react/features/chat/components/native/ChatSearchBar.tsx b/react/features/chat/components/native/ChatSearchBar.tsxnew file mode 100644index 0000000000..08652f5a8f--- /dev/null+++ b/react/features/chat/components/native/ChatSearchBar.tsx@@ -0,0 +1,107 @@+import React, { useCallback } from 'react';+import { Text, TouchableOpacity, View, ViewStyle } from 'react-native';+import { useDispatch, useSelector } from 'react-redux';++import { IReduxState } from '../../../app/types';+import { translate } from '../../../base/i18n/functions.native';+import Icon from '../../../base/icons/components/Icon';+import { IconArrowDown, IconArrowUp } from '../../../base/icons/svg';+import BaseTheme from '../../../base/ui/components/BaseTheme.native';+import Input from '../../../base/ui/components/native/Input';+import { setChatSearchMatchIndex, setChatSearchQuery } from '../../actions.native';+import { getChatSearchMatchIndex, getChatSearchMatches, getChatSearchQuery } from '../../functions';++import styles from './styles';++interface IProps {+ t: Function;+}++/**+ * Renders an always-visible search bar above the chat message list, allowing+ * the user to filter messages and step through matches.+ *+ * @returns {React.ReactElement}+ */+const ChatSearchBar = ({ t }: IProps) => {+ const dispatch = useDispatch();+ const query = useSelector((state: IReduxState) => getChatSearchQuery(state));+ const matches = useSelector((state: IReduxState) => getChatSearchMatches(state));+ const matchIndex = useSelector((state: IReduxState) => getChatSearchMatchIndex(state));++ const hasQuery = query.trim().length > 0;+ const hasMatches = matches.length > 0;++ const _onChangeText = useCallback((text: string) => {+ dispatch(setChatSearchQuery(text));+ }, [ dispatch ]);++ const _onPrevious = useCallback(() => {+ if (!matches.length) {+ return;+ }++ dispatch(setChatSearchMatchIndex((matchIndex - 1 + matches.length) % matches.length));+ }, [ dispatch, matchIndex, matches.length ]);++ const _onNext = useCallback(() => {+ if (!matches.length) {+ return;+ }++ dispatch(setChatSearchMatchIndex((matchIndex + 1) % matches.length));+ }, [ dispatch, matchIndex, matches.length ]);++ const _onSubmitEditing = useCallback(() => {+ _onNext();+ }, [ _onNext ]);++ return (+ <View style = { styles.searchBarContainer as ViewStyle }>+ <Input+ clearable = { true }+ customStyles = {{+ clearButton: styles.searchClearButton,+ container: styles.searchInputContainer,+ input: styles.searchInput+ }}+ onChange = { _onChangeText }+ onSubmitEditing = { _onSubmitEditing }+ placeholder = { t('chat.search.placeholder') }+ returnKeyType = 'search'+ value = { query } />+ { hasQuery && (+ <>+ <Text style = { styles.searchBarCounter }>+ { hasMatches+ ? t('chat.search.resultsCount', {+ current: matchIndex + 1,+ total: matches.length+ })+ : t('chat.search.noResults') }+ </Text>+ <TouchableOpacity+ disabled = { !hasMatches }+ onPress = { _onPrevious }+ style = { styles.searchBarNavButton as ViewStyle }>+ <Icon+ color = { hasMatches ? BaseTheme.palette.icon01 : BaseTheme.palette.icon03 }+ size = { 18 }+ src = { IconArrowUp } />+ </TouchableOpacity>+ <TouchableOpacity+ disabled = { !hasMatches }+ onPress = { _onNext }+ style = { styles.searchBarNavButton as ViewStyle }>+ <Icon+ color = { hasMatches ? BaseTheme.palette.icon01 : BaseTheme.palette.icon03 }+ size = { 18 }+ src = { IconArrowDown } />+ </TouchableOpacity>+ </>+ ) }+ </View>+ );+};++export default translate(ChatSearchBar);diff --git a/react/features/chat/components/native/MessageContainer.tsx b/react/features/chat/components/native/MessageContainer.tsxindex b9b503f421..2aa128d54e 100644--- a/react/features/chat/components/native/MessageContainer.tsx+++ b/react/features/chat/components/native/MessageContainer.tsx@@ -2,14 +2,28 @@ import React, { Component } from 'react';import { FlatList, Text, TextStyle, View, ViewStyle } from 'react-native';import { connect } from 'react-redux';-import { translate } from '../../../base/i18n/functions';-import { IMessageGroup, groupMessagesBySender } from '../../../base/util/messageGrouping';+import { IReduxState } from '../../../app/types';+import { translate } from '../../../base/i18n/functions.native';+import { groupMessagesBySender } from '../../../base/util/messageGrouping';+import { MESSAGE_TYPE_LOCAL, MESSAGE_TYPE_REMOTE } from '../../constants';+import { getActiveChatSearchMatch } from '../../functions';import { IMessage } from '../../types';-import ChatMessageGroup from './ChatMessageGroup';+import ChatMessage from './ChatMessage';import styles from './styles';+/**+ * A single flat list row: one message plus its grouping flags.+ */+interface IMessageRow {+ message: IMessage;+ showAvatar: boolean;+ showDisplayName: boolean;+ showTimestamp: boolean;+}+interface IProps {+ _activeMatch?: IMessage;messages: IMessage[];t: Function;}@@ -23,6 +37,8 @@ class MessageContainer extends Component<IProps, any> {messages: [] as IMessage[]};+ _flatListRef: React.RefObject<FlatList<any>>;+/*** Instantiates a new instance of the component.*@@ -31,10 +47,75 @@ class MessageContainer extends Component<IProps, any> {constructor(props: IProps) {super(props);+ this._flatListRef = React.createRef();this._keyExtractor = this._keyExtractor.bind(this);this._renderListEmptyComponent = this._renderListEmptyComponent.bind(this);- this._renderMessageGroup = this._renderMessageGroup.bind(this);- this._getMessagesGroupedBySender = this._getMessagesGroupedBySender.bind(this);+ this._renderMessage = this._renderMessage.bind(this);+ this._getMessageRows = this._getMessageRows.bind(this);+ this._onScrollToIndexFailed = this._onScrollToIndexFailed.bind(this);+ }++ /**+ * Implements {@code Component#componentDidUpdate}.+ *+ * @inheritdoc+ */+ override componentDidUpdate(prevProps: IProps) {+ const { _activeMatch } = this.props;++ if (_activeMatch && _activeMatch.messageId !== prevProps._activeMatch?.messageId) {+ this._scrollToActiveMatch();+ }+ }++ /**+ * Scrolls the list so the active search match message is visible.+ *+ * @returns {void}+ */+ _scrollToActiveMatch() {+ const { _activeMatch } = this.props;++ if (!_activeMatch) {+ return;+ }++ const data = this._getMessageRows();+ const index = data.findIndex(row => row.message.messageId === _activeMatch.messageId);++ if (index === -1) {+ return;+ }++ requestAnimationFrame(() => {+ this._flatListRef.current?.scrollToIndex({+ animated: true,+ index,+ viewPosition: 0.5+ });+ });+ }++ /**+ * Fallback for when scrollToIndex fires before the target row is measured.+ *+ * @param {Object} info - Info about the failed scroll attempt.+ * @returns {void}+ */+ _onScrollToIndexFailed(info: { averageItemLength: number; index: number; }) {+ // Jump near the target so it renders, then retry.+ this._flatListRef.current?.scrollToOffset({+ animated: false,+ offset: info.averageItemLength * info.index+ });++ setTimeout(() => {+ this._flatListRef.current?.scrollToIndex({+ animated: true,+ index: info.index,+ viewPosition: 0.5+ });+ }, 100);}/**@@ -43,7 +124,7 @@ class MessageContainer extends Component<IProps, any> {* @inheritdoc*/override render() {- const data = this._getMessagesGroupedBySender();+ const data = this._getMessageRows();const noMessages = data.length === 0;return (@@ -59,7 +140,9 @@ class MessageContainer extends Component<IProps, any> {inverted = { Boolean(data.length) }keyExtractor = { this._keyExtractor }keyboardShouldPersistTaps = 'handled'- renderItem = { this._renderMessageGroup }+ onScrollToIndexFailed = { this._onScrollToIndexFailed }+ ref = { this._flatListRef }+ renderItem = { this._renderMessage }style = { noMessages && styles.emptyListStyle } />);}@@ -67,13 +150,11 @@ class MessageContainer extends Component<IProps, any> {/*** Key extractor for the flatlist.*- * @param {Object} _item - The flatlist item that we need the key to be- * generated for.- * @param {number} index - The index of the element.+ * @param {IMessageRow} item - The row whose key we need to generate.* @returns {string}*/- _keyExtractor(_item: Object, index: number) {- return `key_${index}`;+ _keyExtractor(item: IMessageRow) {+ return item.message.messageId;}/**@@ -98,24 +179,49 @@ class MessageContainer extends Component<IProps, any> {/*** Renders a single chat message.*- * @param {Array<Object>} messages - The chat message to render.+ * @param {Object} row - The row containing the message and its grouping flags.* @returns {React$Element<*>}*/- _renderMessageGroup({ item: group }: { item: IMessageGroup<IMessage>; }) {- const { messages } = group;-- return <ChatMessageGroup messages = { messages } />;+ _renderMessage({ item }: { item: IMessageRow; }) {+ return (+ <ChatMessage+ message = { item.message }+ showAvatar = { item.showAvatar }+ showDisplayName = { item.showDisplayName }+ showTimestamp = { item.showTimestamp } />+ );}/**- * Returns an array of message groups, where each group is an array of messages- * grouped by the sender.+ * Builds one row per message with its grouping flags.*- * @returns {Array<Array<Object>>}+ * @returns {IMessageRow[]}*/- _getMessagesGroupedBySender() {- return groupMessagesBySender(this.props.messages);+ _getMessageRows(): IMessageRow[] {+ const rows: IMessageRow[] = [];++ for (const group of groupMessagesBySender(this.props.messages)) {+ const groupType = group.messages[0].messageType;+ const oldestIndex = group.messages.length - 1;++ group.messages.forEach((message, index) => {+ rows.push({+ message,+ showAvatar: groupType !== MESSAGE_TYPE_LOCAL && index === oldestIndex,+ showDisplayName: groupType === MESSAGE_TYPE_REMOTE && index === oldestIndex,+ showTimestamp: index === 0+ });+ });+ }++ return rows;}}-export default translate(connect()(MessageContainer));+function _mapStateToProps(state: IReduxState) {+ return {+ _activeMatch: getActiveChatSearchMatch(state)+ };+}++export default translate(connect(_mapStateToProps)(MessageContainer));diff --git a/react/features/chat/components/native/styles.ts b/react/features/chat/components/native/styles.tsindex 536c0eb511..96975f57ac 100644--- a/react/features/chat/components/native/styles.ts+++ b/react/features/chat/components/native/styles.ts@@ -81,6 +81,66 @@ export default {underlayColor: 'transparent'},+ activeMatchMessageBubble: {+ backgroundColor: BaseTheme.palette.warning02+ },++ chatMessageHighlight: {+ backgroundColor: BaseTheme.palette.action02,+ color: BaseTheme.palette.text01+ },++ chatMessageHighlightActive: {+ backgroundColor: BaseTheme.palette.action01,+ color: BaseTheme.palette.text01+ },++ searchBarContainer: {+ alignItems: 'center',+ backgroundColor: BaseTheme.palette.ui03,+ borderColor: BaseTheme.palette.ui03,+ borderRadius: BaseTheme.shape.borderRadius,+ borderWidth: 2,+ flexDirection: 'row',+ height: 40,+ marginBottom: BaseTheme.spacing[1],+ marginHorizontal: BaseTheme.spacing[3],+ marginTop: BaseTheme.spacing[2],+ paddingHorizontal: BaseTheme.spacing[2]+ },++ searchBarCounter: {+ ...BaseTheme.typography.labelRegular,+ color: BaseTheme.palette.text03,+ marginHorizontal: BaseTheme.spacing[1]+ },++ searchBarNavButton: {+ alignItems: 'center',+ alignSelf: 'stretch',+ justifyContent: 'center',+ padding: BaseTheme.spacing[1]+ },++ searchClearButton: {+ alignItems: 'center',+ height: 40,+ justifyContent: 'center',+ top: 0+ },++ searchInputContainer: {+ flex: 1,+ marginBottom: 0+ },++ searchInput: {+ backgroundColor: 'transparent',+ borderWidth: 0,+ height: 40,+ paddingHorizontal: 0+ },+/*** Wrapper View for the avatar.*/diff --git a/react/features/chat/components/web/Chat.tsx b/react/features/chat/components/web/Chat.tsxindex 53e40efb4d..fca18631d0 100644--- a/react/features/chat/components/web/Chat.tsx+++ b/react/features/chat/components/web/Chat.tsx@@ -128,6 +128,8 @@ const useStyles = makeStyles<{position: 'relative',transition: _isResizing ? undefined : 'width .16s ease-in-out',width: `${width}px`,+ height: '100%',+ minHeight: 0,zIndex: 300,// On non-touch devices (desktop), show handle on hover@@ -178,6 +180,7 @@ const useStyles = makeStyles<{chatPanel: {display: 'flex',flexDirection: 'column',+ minHeight: 0,// extract header + tabs heightheight: 'calc(100% - 110px)'@@ -185,7 +188,8 @@ const useStyles = makeStyles<{chatPanelNoTabs: {// extract header height- height: 'calc(100% - 60px)'+ height: 'calc(100% - 60px)',+ minHeight: 0},pollsPanel: {diff --git a/react/features/chat/components/web/ChatHeader.tsx b/react/features/chat/components/web/ChatHeader.tsxindex 7d6ce22a6f..694fc9f8ed 100644--- a/react/features/chat/components/web/ChatHeader.tsx+++ b/react/features/chat/components/web/ChatHeader.tsx@@ -1,13 +1,32 @@-import React, { useCallback } from 'react';+import React, { useCallback, useEffect, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';import { useDispatch, useSelector } from 'react-redux';+import { makeStyles } from 'tss-react/mui';import Icon from '../../../base/icons/components/Icon';-import { IconCloseLarge } from '../../../base/icons/svg';+import {+ IconArrowDown,+ IconArrowUp,+ IconCloseCircle,+ IconCloseLarge,+ IconSearch+} from '../../../base/icons/svg';+import Input from '../../../base/ui/components/web/Input';import { isFileSharingEnabled } from '../../../file-sharing/functions.any';-import { toggleChat } from '../../actions.web';+import {+ clearChatSearch,+ setChatSearchMatchIndex,+ setChatSearchQuery,+ toggleChat+} from '../../actions.web';import { ChatTabs } from '../../constants';-import { getFocusedTab, isChatDisabled } from '../../functions';+import {+ getChatSearchMatchIndex,+ getChatSearchMatches,+ getChatSearchQuery,+ getFocusedTab,+ isChatDisabled+} from '../../functions';interface IProps {@@ -32,21 +51,103 @@ interface IProps {onCancel: Function;}+const useStyles = makeStyles()(theme => {+ return {+ searchContainer: {+ display: 'flex',+ alignItems: 'center',+ gap: theme.spacing(1),+ flex: 1,+ marginRight: theme.spacing(3),+ backgroundColor: theme.palette.inputFieldBackground,+ borderRadius: theme.shape.borderRadius,+ paddingRight: theme.spacing(2),++ '&:focus-within': {+ boxShadow: `0px 0px 0px 2px ${theme.palette.inputFieldFocus}`+ }+ },+ inputWrapper: {+ flex: 1,+ minWidth: 0+ },+ searchInputField: {+ backgroundColor: 'transparent !important',+ background: 'transparent !important',+ border: '0 !important',+ boxShadow: 'none !important',+ paddingRight: '4px !important',++ '&:focus': {+ boxShadow: 'none !important'+ }+ },+ divider: {+ width: '1px',+ alignSelf: 'stretch',+ margin: `${theme.spacing(1)}px ${theme.spacing(1)}px`,+ backgroundColor: 'rgba(255, 255, 255, 0.15)'+ },+ resultsCount: {+ ...theme.typography.labelRegular,+ color: theme.palette.text02,+ whiteSpace: 'nowrap',+ minWidth: '48px',+ textAlign: 'center' as const+ },+ navButton: {+ cursor: 'pointer',+ opacity: 1,++ '&.disabled': {+ cursor: 'default',+ opacity: 0.3+ }+ },+ headerActions: {+ display: 'flex',+ alignItems: 'center',+ gap: theme.spacing(2)+ }+ };+});+/*** Custom header of the {@code ChatDialog}.** @returns {React$Element<any>}*/-function ChatHeader({ className, isCCTabEnabled, isPollsEnabled }: IProps) {+function ChatHeader({ className, isCCTabEnabled, isPollsEnabled, onCancel: onCancelProp }: IProps) {+ const { classes, cx } = useStyles();const dispatch = useDispatch();const { t } = useTranslation();const _isChatDisabled = useSelector(isChatDisabled);const focusedTab = useSelector(getFocusedTab);const fileSharingTabEnabled = useSelector(isFileSharingEnabled);+ const [ isSearchOpen, setIsSearchOpen ] = useState(false);++ const query = useSelector(getChatSearchQuery);+ const matches = useSelector(getChatSearchMatches);+ const matchIndex = useSelector(getChatSearchMatchIndex);+ const hasMatches = matches.length > 0;+ // Local, un-debounced copy of the input value so typing feels instant, while the+ // Redux dispatch (which drives the expensive getChatSearchMatches filter) is debounced.+ const [ inputValue, setInputValue ] = useState(query);+ const debounceRef = useRef<ReturnType<typeof setTimeout>>();++ // Keep the local input in sync when the query is cleared/reset from elsewhere+ // (e.g. clearChatSearch dispatched on tab switch or panel close).+ useEffect(() => {+ setInputValue(query);+ }, [ query ]);const onCancel = useCallback(() => {- dispatch(toggleChat());- }, []);+ if (onCancelProp) {+ onCancelProp();+ } else {+ dispatch(toggleChat());+ }+ }, [ onCancelProp ]);const onKeyPressHandler = useCallback(e => {if (onCancel && (e.key === ' ' || e.key === 'Enter')) {@@ -55,6 +156,78 @@ function ChatHeader({ className, isCCTabEnabled, isPollsEnabled }: IProps) {}}, []);+ const onSearchToggle = useCallback(() => {+ setIsSearchOpen(open => !open);+ }, []);++ const onSearchClose = useCallback(() => {+ if (debounceRef.current) {+ clearTimeout(debounceRef.current);+ }+ dispatch(clearChatSearch());+ setIsSearchOpen(false);+ }, [ dispatch ]);++ const onQueryChange = useCallback((value: string) => {+ setInputValue(value);++ if (debounceRef.current) {+ clearTimeout(debounceRef.current);+ }+ debounceRef.current = setTimeout(() => {+ dispatch(setChatSearchQuery(value));+ }, 200);+ }, [ dispatch ]);++ const onNext = useCallback(() => {+ if (!hasMatches) {+ return;+ }+ dispatch(setChatSearchMatchIndex((matchIndex + 1) % matches.length));+ }, [ dispatch, hasMatches, matchIndex, matches.length ]);++ const onPrev = useCallback(() => {+ if (!hasMatches) {+ return;+ }+ dispatch(setChatSearchMatchIndex((matchIndex - 1 + matches.length) % matches.length));+ }, [ dispatch, hasMatches, matchIndex, matches.length ]);++ const onSearchKeyDown = useCallback((e: React.KeyboardEvent) => {+ if (e.key === 'Enter') {+ e.preventDefault();+ e.shiftKey ? onPrev() : onNext();+ } else if (e.key === 'Escape') {+ onSearchClose();+ }+ }, [ onNext, onPrev, onSearchClose ]);++ // Clear any pending debounced dispatch on unmount so it doesn't fire after teardown.+ useEffect(() => {+ return () => {+ if (debounceRef.current) {+ clearTimeout(debounceRef.current);+ }+ };+ }, []);++ // Keep matchIndex in bounds whenever the match set shrinks (new query, or a message+ // disappearing) so `matches[matchIndex]` never reads undefined downstream.+ useEffect(() => {+ if (matchIndex >= matches.length && matches.length > 0) {+ dispatch(setChatSearchMatchIndex(0));+ }+ }, [ matches.length, matchIndex, dispatch ]);++ // Close the search bar if the user switches away from the Chat tab (e.g. to Polls/CC/+ // File sharing) without closing the whole panel — search only makes sense on the Chat tab.+ useEffect(() => {+ if (isSearchOpen && focusedTab !== ChatTabs.CHAT) {+ setIsSearchOpen(false);+ dispatch(clearChatSearch());+ }+ }, [ focusedTab ]);+let title = 'chat.title';if (!_isChatDisabled && focusedTab === ChatTabs.CHAT) {@@ -72,21 +245,76 @@ function ChatHeader({ className, isCCTabEnabled, isPollsEnabled }: IProps) {return null;}+ // Only show the search toggle on the actual chat message tab — searching+ // polls/CC/file-sharing isn't in scope here.+ const showSearchToggle = !_isChatDisabled && focusedTab === ChatTabs.CHAT;+return (<divclassName = { className || 'chat-dialog-header' }>- <span- aria-level = { 1 }- role = 'heading'>- { t(title) }- </span>- <Icon- ariaLabel = { t('toolbar.closeChat') }- onClick = { onCancel }- onKeyPress = { onKeyPressHandler }- role = 'button'- src = { IconCloseLarge }- tabIndex = { 0 } />+ {isSearchOpen ? (+ <div+ className = { classes.searchContainer }+ onKeyDown = { onSearchKeyDown }>+ <div className = { classes.inputWrapper }>+ <Input+ autoFocus = { true }+ icon = { IconSearch }+ id = 'chat-search-input'+ inputClassName = { classes.searchInputField }+ onChange = { onQueryChange }+ placeholder = { t('chat.search.placeholder') }+ value = { inputValue } />+ </div>+ <span className = { classes.resultsCount }>+ {query.trim()+ ? t('chat.search.resultsCount', {+ current: hasMatches ? matchIndex + 1 : 0,+ total: matches.length+ })+ : null}+ </span>+ <Icon+ ariaLabel = { t('chat.search.previous') }+ className = { cx(classes.navButton, !hasMatches && 'disabled') }+ onClick = { onPrev }+ src = { IconArrowUp } />+ <Icon+ ariaLabel = { t('chat.search.next') }+ className = { cx(classes.navButton, !hasMatches && 'disabled') }+ onClick = { onNext }+ src = { IconArrowDown } />+ <span className = { classes.divider } />+ <Icon+ ariaLabel = { t('chat.search.close') }+ onClick = { onSearchClose }+ size = { 18 }+ src = { IconCloseCircle } />+ </div>+ ) : (+ <span+ aria-level = { 1 }+ role = 'heading'>+ { t(title) }+ </span>+ )}+ <div className = { classes.headerActions }>+ {!isSearchOpen && showSearchToggle && (+ <Icon+ ariaLabel = { t('chat.search.open') }+ onClick = { onSearchToggle }+ role = 'button'+ src = { IconSearch }+ tabIndex = { 0 } />+ )}+ <Icon+ ariaLabel = { t('toolbar.closeChat') }+ onClick = { onCancel }+ onKeyPress = { onKeyPressHandler }+ role = 'button'+ src = { IconCloseLarge }+ tabIndex = { 0 } />+ </div></div>);}diff --git a/react/features/chat/components/web/ChatMessage.tsx b/react/features/chat/components/web/ChatMessage.tsxindex feac8c8d9f..38427f3f37 100644--- a/react/features/chat/components/web/ChatMessage.tsx+++ b/react/features/chat/components/web/ChatMessage.tsx@@ -1,5 +1,5 @@import { Theme } from '@mui/material';-import React, { useCallback, useMemo, useState } from 'react';+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { connect } from 'react-redux';import { makeStyles } from 'tss-react/mui';@@ -9,7 +9,8 @@ import { getParticipantById, getParticipantDisplayName, isPrivateChatEnabled } fimport Popover from '../../../base/popover/components/Popover.web';import Message from '../../../base/react/components/web/Message';import { MESSAGE_TYPE_LOCAL } from '../../constants';-import { getDisplayNameSuffix, getFormattedTimestamp, getMessageText, getPrivateNoticeMessage, isFileMessage } from '../../functions';+// AFTER+import { getActiveChatSearchMatch, getChatSearchQuery, getDisplayNameSuffix, getFormattedTimestamp, getMessageText, getPrivateNoticeMessage, isFileMessage } from '../../functions';import { IChatMessageProps } from '../../types';import FileMessage from './FileMessage';@@ -19,6 +20,8 @@ import ReactButton from './ReactButton';interface IProps extends IChatMessageProps {className?: string;enablePrivateChat?: boolean;+ isActiveSearchMatch?: boolean;+ searchQuery?: string;shouldDisplayMenuOnRight?: boolean;state?: IReduxState;}@@ -103,6 +106,20 @@ const useStyles = makeStyles()((theme: Theme) => {backgroundColor: theme.palette.chatMessagePrivate}},+ searchMatchActive: {+ outline: `2px solid ${theme.palette.action01}`,+ outlineOffset: '2px',+ animation: '$searchMatchFlash 1.4s ease-out'+ },++ '@keyframes searchMatchFlash': {+ '0%': {+ backgroundColor: theme.palette.warning01+ },+ '100%': {+ backgroundColor: 'transparent'+ }+ },sideBySideContainer: {display: 'flex',flexDirection: 'row',@@ -157,7 +174,14 @@ const useStyles = makeStyles()((theme: Theme) => {...theme.typography.bodyShortRegular,color: theme.palette.chatMessageText,whiteSpace: 'pre-wrap',- wordBreak: 'break-word'+ wordBreak: 'break-word',++ '& mark': {+ backgroundColor: theme.palette.warning01,+ color: theme.palette.text04,+ borderRadius: '2px',+ padding: '0 1px'+ }},privateMessageNotice: {...theme.typography.labelRegular,@@ -212,6 +236,8 @@ const ChatMessage = ({state,showDisplayName,shouldDisplayMenuOnRight,+ isActiveSearchMatch,+ searchQuery,enablePrivateChat,knocking,t@@ -219,6 +245,33 @@ const ChatMessage = ({const { classes, cx } = useStyles();const [ isHovered, setIsHovered ] = useState(false);const [ isReactionsOpen, setIsReactionsOpen ] = useState(false);+ const messageRef = useRef<HTMLDivElement>(null);++ useEffect(() => {+ if (!isActiveSearchMatch || !messageRef.current) {+ return;+ }++ const messageElement = messageRef.current;+ const container = messageElement.closest('#chatconversation') as HTMLElement | null;++ if (!container) {+ return;+ }++ const messageRect = messageElement.getBoundingClientRect();+ const containerRect = container.getBoundingClientRect();++ const offset = messageRect.top+ - containerRect.top+ - (containerRect.height / 2)+ + (messageRect.height / 2);++ container.scrollTo({+ top: container.scrollTop + offset,+ behavior: 'smooth'+ });+ }, [ isActiveSearchMatch ]);const handleMouseEnter = useCallback(() => {setIsHovered(true);@@ -374,8 +427,10 @@ const ChatMessage = ({className,message.privateMessage && 'privatemessage',message.lobbyChat && !knocking && 'lobbymessage',- isFileMessage(message) && 'file'- ) }>+ isFileMessage(message) && 'file',+ isActiveSearchMatch && classes.searchMatchActive+ ) }+ ref = { messageRef }><div className = { classes.replyWrapper }><div className = { cx('messagecontent', classes.messageContent) }>{showDisplayName && _renderDisplayName()}@@ -391,6 +446,7 @@ const ChatMessage = ({} />) : (<Message+ highlightQuery = { searchQuery }screenReaderHelpText = { message.messageType === MESSAGE_TYPE_LOCAL? t<string>('chat.messageAccessibleTitleMe'): t<string>('chat.messageAccessibleTitle', {@@ -452,6 +508,9 @@ const ChatMessage = ({function _mapStateToProps(state: IReduxState, { message }: IProps) {const { knocking } = state['features/lobby'];+ const activeSearchMatch = getActiveChatSearchMatch(state);+ const isActiveSearchMatch = Boolean(activeSearchMatch && activeSearchMatch.messageId === message.messageId);+const participant = getParticipantById(state, message.participantId);// For visitor private messages, participant will be undefined but we should still allow private chat@@ -470,6 +529,8 @@ function _mapStateToProps(state: IReduxState, { message }: IProps) {return {shouldDisplayMenuOnRight,enablePrivateChat,+ isActiveSearchMatch,+ searchQuery: getChatSearchQuery(state),knocking,state};diff --git a/react/features/chat/functions.ts b/react/features/chat/functions.tsindex 5537e7c33f..c6a12d3f9a 100644--- a/react/features/chat/functions.ts+++ b/react/features/chat/functions.ts@@ -3,6 +3,7 @@ import aliases from 'react-emoji-render/data/aliases';// eslint-disable-next-line lines-around-comment// @ts-expect-errorimport emojiAsciiAliases from 'react-emoji-render/data/asciiAliases';+import { createSelector } from 'reselect';import { IReduxState } from '../app/types';import { getLocalizedDateFormatter } from '../base/i18n/dateUtil';@@ -229,6 +230,41 @@ export function getMessageText(message: IMessage): string {: message.message;}+/**+ * Escapes regexp special characters in a string.+ *+ * @param {string} value - The string to escape.+ * @returns {string}+ */+export function escapeSearchRegExp(value: string): string {+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+}++/**+ * Splits message text into segments, flagging which ones match the search+ * query (case-insensitive), so callers can render matches with a highlight+ * style. Shared between web and native so both wrap matches identically.+ *+ * @param {string} text - The message text.+ * @param {string} query - The search query.+ * @returns {Array<Object>}+ */+export function getHighlightSegments(text: string, query: string): Array<{ match: boolean; text: string; }> {+ if (!query) {+ return [ { match: false,+ text } ];+ }++ const regexp = new RegExp(`(${escapeSearchRegExp(query)})`, 'gi');++ return text+ .split(regexp)+ .filter(part => part.length > 0)+ .map(part => ({+ match: part.toLowerCase() === query.toLowerCase(),+ text: part+ }));+}/*** Returns whether a message can be replied to.@@ -357,3 +393,68 @@ export function getDisplayNameSuffix(message: IMessage): string {export function isFileMessage(message: IMessage): boolean {return Boolean(message?.fileMetadata);}++/**+ * Returns the current chat search query.+ *+ * @param {IReduxState} state - The redux state.+ * @returns {string}+ */+export function getChatSearchQuery(state: IReduxState): string {+ return state['features/chat'].searchQuery || '';+}++/**+ * Stable empty-array reference returned when there is no active search query, so repeated+ * "no query" calls return the same reference instead of a new empty array each time.+ */+const NO_SEARCH_MATCHES: IMessage[] = [];++const _getMessages = (state: IReduxState) => state['features/chat'].messages;++/**+ * Returns all messages matching the current search query, in display order.+ * Reaction and file messages are excluded since they have no searchable text.+ * Memoized: only recomputes when messages or the search query change.+ *+ * @returns {IMessage[]}+ */+export const getChatSearchMatches = createSelector(+ _getMessages,+ getChatSearchQuery,+ (messages, searchQuery): IMessage[] => {+ const query = searchQuery?.trim().toLowerCase();++ if (!query) {+ return NO_SEARCH_MATCHES;+ }++ return messages.filter(message =>+ !message.isReaction+ && !isFileMessage(message)+ && getMessageText(message).toLowerCase().includes(query));+ }+);++/**+ * Returns the index of the currently focused search match.+ *+ * @param {IReduxState} state - The redux state.+ * @returns {number}+ */+export function getChatSearchMatchIndex(state: IReduxState): number {+ return state['features/chat'].searchMatchIndex || 0;+}++/**+ * Returns the message that is the currently focused search match, if any.+ * Memoized via getChatSearchMatches — this is called from every ChatMessage's+ * mapStateToProps, so keeping it cheap matters.+ *+ * @returns {IMessage | undefined}+ */+export const getActiveChatSearchMatch = createSelector(+ getChatSearchMatches,+ getChatSearchMatchIndex,+ (matches, index): IMessage | undefined => matches[index]+);diff --git a/react/features/chat/reducer.ts b/react/features/chat/reducer.tsindex 92be458cbe..1ace41baf3 100644--- a/react/features/chat/reducer.ts+++ b/react/features/chat/reducer.ts@@ -7,6 +7,7 @@ import { IVisitorChatParticipant } from '../visitors/types';import {ADD_MESSAGE,ADD_MESSAGE_REACTION,+ CLEAR_CHAT_SEARCH,CLEAR_CHAT_STATE,CLOSE_CHAT,EDIT_MESSAGE,@@ -14,6 +15,8 @@ import {OPEN_CHAT,REMOVE_LOBBY_CHAT_PARTICIPANT,SET_CHAT_IS_RESIZING,+ SET_CHAT_SEARCH_MATCH_INDEX,+ SET_CHAT_SEARCH_QUERY,SET_CHAT_WIDTH,SET_FOCUSED_TAB,SET_LOBBY_CHAT_ACTIVE_STATE,@@ -33,6 +36,8 @@ const DEFAULT_STATE = {unreadMessagesCount: 0,unreadFilesCount: 0,privateMessageRecipient: undefined,+ searchQuery: '',+ searchMatchIndex: 0,lobbyMessageRecipient: undefined,isLobbyChatActive: false,focusedTab: undefined,@@ -57,6 +62,8 @@ export interface IChatState {messages: IMessage[];notifyPrivateRecipientsChangedTimestamp?: number;privateMessageRecipient?: IParticipant | IVisitorChatParticipant;+ searchMatchIndex: number;+ searchQuery: string;unreadFilesCount: number;unreadMessagesCount: number;width: {@@ -141,6 +148,13 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, ac};}+ case CLEAR_CHAT_SEARCH:+ return {+ ...state,+ searchQuery: '',+ searchMatchIndex: 0+ };+case CLEAR_CHAT_STATE:return {...DEFAULT_STATE,@@ -171,6 +185,19 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, ac};}+ case SET_CHAT_SEARCH_MATCH_INDEX:+ return {+ ...state,+ searchMatchIndex: action.index+ };++ case SET_CHAT_SEARCH_QUERY:+ return {+ ...state,+ searchQuery: action.query,+ searchMatchIndex: 0+ };+case SET_PRIVATE_MESSAGE_RECIPIENT:return {...state,@@ -191,7 +218,9 @@ ReducerRegistry.register<IChatState>('features/chat', (state = DEFAULT_STATE, aclastReadMessage: state.messages[navigator.product === 'ReactNative' ? 0 : state.messages.length - 1],privateMessageRecipient: action.participant,- isLobbyChatActive: false+ isLobbyChatActive: false,+ searchQuery: '',+ searchMatchIndex: 0};case SET_LOBBY_CHAT_RECIPIENT:diff --git a/react/features/chat/types.ts b/react/features/chat/types.tsindex 4a380900c6..f82709e6ed 100644--- a/react/features/chat/types.ts+++ b/react/features/chat/types.ts@@ -70,6 +70,17 @@ export interface IChatMessageProps extends WithTranslation {*/gifEnabled?: boolean;+ /**+ * Case-insensitive search query whose matches in the message text should be highlighted.+ * Left undefined/empty for no highlighting.+ */+ highlightQuery?: string;++ /**+ * Whether this message is the currently focused search match (for prev/next navigation).+ */+ isActiveMatch?: boolean;+/*** Whether current participant is currently knocking in the lobby room.*/