@@ -11,6 +11,7 @@ import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionS
1111import useSearchSelector from '@hooks/useSearchSelector' ;
1212import { canUseTouchScreen } from '@libs/DeviceCapabilities' ;
1313import { formatSectionsFromSearchTerm , getFilteredRecentAttendees , getParticipantsOption } from '@libs/OptionsListUtils' ;
14+ import { doesPersonalDetailMatchSearchTerm } from '@libs/OptionsListUtils/searchMatchUtils' ;
1415import type { OptionData } from '@libs/ReportUtils' ;
1516import { getDisplayNameForParticipant } from '@libs/ReportUtils' ;
1617import Navigation from '@navigation/Navigation' ;
@@ -76,18 +77,19 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
7677 [ personalDetails , recentAttendees , currentUserEmail , currentUserAccountID , shouldAllowNameOnlyOptions ] ,
7778 ) ;
7879
79- const { searchTerm, setSearchTerm, availableOptions, selectedOptions, setSelectedOptions, toggleSelection, areOptionsInitialized, onListEndReached} = useSearchSelector ( {
80- selectionMode : CONST . SEARCH_SELECTOR . SELECTION_MODE_MULTI ,
81- searchContext : CONST . SEARCH_SELECTOR . SEARCH_CONTEXT_GENERAL ,
82- maxRecentReportsToShow : CONST . IOU . MAX_RECENT_REPORTS_TO_SHOW ,
83- includeUserToInvite : true ,
84- excludeLogins : CONST . EXPENSIFY_EMAILS_OBJECT ,
85- includeRecentReports : true ,
86- shouldInitialize : didScreenTransitionEnd ,
87- includeCurrentUser : true ,
88- recentAttendees : recentAttendeeLists ,
89- shouldAllowNameOnlyOptions,
90- } ) ;
80+ const { searchTerm, debouncedSearchTerm, setSearchTerm, availableOptions, selectedOptions, setSelectedOptions, toggleSelection, areOptionsInitialized, onListEndReached} =
81+ useSearchSelector ( {
82+ selectionMode : CONST . SEARCH_SELECTOR . SELECTION_MODE_MULTI ,
83+ searchContext : CONST . SEARCH_SELECTOR . SEARCH_CONTEXT_GENERAL ,
84+ maxRecentReportsToShow : CONST . IOU . MAX_RECENT_REPORTS_TO_SHOW ,
85+ includeUserToInvite : true ,
86+ excludeLogins : CONST . EXPENSIFY_EMAILS_OBJECT ,
87+ includeRecentReports : true ,
88+ shouldInitialize : didScreenTransitionEnd ,
89+ includeCurrentUser : true ,
90+ recentAttendees : recentAttendeeLists ,
91+ shouldAllowNameOnlyOptions,
92+ } ) ;
9193
9294 const { sections, headerMessage} = useMemo ( ( ) => {
9395 const newSections = [ ] ;
@@ -104,7 +106,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
104106 }
105107
106108 const formattedResults = formatSectionsFromSearchTerm (
107- searchTerm . trim ( ) . toLowerCase ( ) ,
109+ debouncedSearchTerm . trim ( ) . toLowerCase ( ) ,
108110 selectedOptions ,
109111 chatOptions . recentReports ,
110112 chatOptions . personalDetails ,
@@ -116,7 +118,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
116118 undefined ,
117119 reportAttributesDerived ,
118120 ) ;
119- const selectedCurrentUser = formattedResults . section . data . find ( ( option ) => option . accountID === chatOptions . currentUserOption ?. accountID ) ;
121+ const selectedCurrentUser = formattedResults . section . data . find ( ( option ) => option . accountID === currentUserAccountID ) ;
120122
121123 // If the current user is already selected, remove them from the recent reports and personal details
122124 if ( selectedCurrentUser ) {
@@ -128,12 +130,13 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
128130 // Falls back to creating from personal details to handle pagination edge cases
129131 if ( ! selectedCurrentUser ) {
130132 let currentUserOptionToShow = chatOptions . currentUserOption ;
131-
132- // Fallback: create current user option from personalDetails if not in paginated results
133- if ( ! currentUserOptionToShow && currentUserAccountID && personalDetails ?. [ currentUserAccountID ] ) {
134- currentUserOptionToShow = {
135- ...getParticipantsOption ( personalDetails [ currentUserAccountID ] , personalDetails ) ,
136- } as OptionData ;
133+ const currentUserDetails = currentUserAccountID ? personalDetails ?. [ currentUserAccountID ] : undefined ;
134+ if ( ! currentUserOptionToShow && currentUserAccountID && currentUserDetails ) {
135+ const candidateOption = getParticipantsOption ( currentUserDetails , personalDetails ) as OptionData ;
136+ const trimmedSearchTerm = debouncedSearchTerm . trim ( ) . toLowerCase ( ) ;
137+ if ( ! trimmedSearchTerm || doesPersonalDetailMatchSearchTerm ( candidateOption , currentUserAccountID , trimmedSearchTerm ) ) {
138+ currentUserOptionToShow = candidateOption ;
139+ }
137140 }
138141
139142 if ( currentUserOptionToShow ) {
@@ -187,7 +190,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate,
187190 } , [
188191 areOptionsInitialized ,
189192 availableOptions ,
190- searchTerm ,
193+ debouncedSearchTerm ,
191194 selectedOptions ,
192195 privateIsArchivedMap ,
193196 currentUserAccountID ,
0 commit comments