@@ -45,7 +45,6 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
4545 const { options, areOptionsInitialized} = useOptionsList ( {
4646 shouldInitialize : didScreenTransitionEnd ,
4747 } ) ;
48-
4948 const [ isSearchingForReports ] = useOnyx ( ONYXKEYS . IS_SEARCHING_FOR_REPORTS , { canBeMissing : false , initWithStoredValues : false } ) ;
5049 const [ reportAttributesDerived ] = useOnyx ( ONYXKEYS . DERIVED . REPORT_ATTRIBUTES , { canBeMissing : true , selector : ( val ) => val ?. reports } ) ;
5150 const [ selectedOptions , setSelectedOptions ] = useState < OptionData [ ] > ( [ ] ) ;
@@ -64,6 +63,7 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
6463 } ,
6564 {
6665 excludeLogins : CONST . EXPENSIFY_EMAILS_OBJECT ,
66+ includeCurrentUser : true ,
6767 } ,
6868 ) ;
6969 } , [ areOptionsInitialized , options . personalDetails , options . reports ] ) ;
@@ -73,12 +73,21 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
7373 } , [ defaultOptions , selectedOptions ] ) ;
7474
7575 const chatOptions = useMemo ( ( ) => {
76- return filterAndOrderOptions ( unselectedOptions , cleanSearchTerm , {
76+ const filteredOptions = filterAndOrderOptions ( unselectedOptions , cleanSearchTerm , {
7777 selectedOptions,
7878 excludeLogins : CONST . EXPENSIFY_EMAILS_OBJECT ,
7979 maxRecentReportsToShow : CONST . IOU . MAX_RECENT_REPORTS_TO_SHOW ,
8080 canInviteUser : false ,
8181 } ) ;
82+
83+ const { currentUserOption} = unselectedOptions ;
84+
85+ // Ensure current user is not in personalDetails when they should be excluded
86+ if ( currentUserOption ) {
87+ filteredOptions . personalDetails = filteredOptions . personalDetails . filter ( ( detail ) => detail . accountID !== currentUserOption . accountID ) ;
88+ }
89+
90+ return filteredOptions ;
8291 } , [ unselectedOptions , cleanSearchTerm , selectedOptions ] ) ;
8392
8493 const { sections, headerMessage} = useMemo ( ( ) => {
@@ -100,18 +109,26 @@ function SearchFiltersParticipantsSelector({initialAccountIDs, onFiltersUpdate}:
100109
101110 const selectedCurrentUser = formattedResults . section . data . find ( ( option ) => option . accountID === chatOptions . currentUserOption ?. accountID ) ;
102111
103- if ( chatOptions . currentUserOption ) {
112+ // If the current user is already selected, remove them from the recent reports and personal details
113+ if ( selectedCurrentUser ) {
114+ chatOptions . recentReports = chatOptions . recentReports . filter ( ( report ) => report . accountID !== selectedCurrentUser . accountID ) ;
115+ chatOptions . personalDetails = chatOptions . personalDetails . filter ( ( detail ) => detail . accountID !== selectedCurrentUser . accountID ) ;
116+ }
117+
118+ // If the current user is not selected, add them to the top of the list
119+ if ( ! selectedCurrentUser && chatOptions . currentUserOption ) {
104120 const formattedName = getDisplayNameForParticipant ( {
105121 accountID : chatOptions . currentUserOption . accountID ,
106122 shouldAddCurrentUserPostfix : true ,
107123 personalDetailsData : personalDetails ,
108124 } ) ;
109- if ( selectedCurrentUser ) {
110- selectedCurrentUser . text = formattedName ;
111- } else {
112- chatOptions . currentUserOption . text = formattedName ;
113- chatOptions . recentReports = [ chatOptions . currentUserOption , ...chatOptions . recentReports ] ;
114- }
125+ chatOptions . currentUserOption . text = formattedName ;
126+
127+ newSections . push ( {
128+ title : '' ,
129+ data : [ chatOptions . currentUserOption ] ,
130+ shouldShow : true ,
131+ } ) ;
115132 }
116133
117134 newSections . push ( formattedResults . section ) ;
0 commit comments