diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 9934880eb905..ede8bdcbb060 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -314,6 +314,9 @@ function getSearchText(report, reportName, personalDetailList, isChatRoomOrPolic // so that we can match emails that have dots without explicitly writing the dots (e.g: fistlast@domain will match first.last@domain) // More info https://github.com/Expensify/App/issues/8007 searchTerms = searchTerms.concat([personalDetail.displayName, personalDetail.login, personalDetail.login.replace(/\.(?=[^\s@]*@)/g, '')]); + } else if (personalDetail.displayName) { + // For unknown users, if login is not set and displayName is set, then set searchText on the basis of displayName + searchTerms = searchTerms.concat([personalDetail.displayName, personalDetail.displayName.replace(/\.(?=[^\s@]*@)/g, '')]); } } } @@ -681,12 +684,12 @@ function getOptions( allPersonalDetailsOptions = lodashOrderBy(allPersonalDetailsOptions, [(personalDetail) => personalDetail.text && personalDetail.text.toLowerCase()], 'asc'); } - // Always exclude already selected options and the currently logged in user - const loginOptionsToExclude = [...selectedOptions, {login: currentUserLogin}]; - - _.each(excludeLogins, (login) => { - loginOptionsToExclude.push({login}); - }); + // Always exclude already selected options and the currently logged in user (accountID) + const accountIDOptionsToExclude = [...selectedOptions, {accountID: currentUserAccountID}]; + // TODO: make this convert logins to accountIDs OR replace these all with accountIDs + // _.each(excludeLogins, (login) => { + // accountIDOptionsToExclude.push({accountID: }); + // }); if (includeRecentReports) { for (let i = 0; i < allReportOptions.length; i++) { @@ -701,12 +704,12 @@ function getOptions( reportOption.isPolicyExpenseChat && reportOption.ownerEmail === currentUserLogin && includeOwnedWorkspaceChats && !reportOption.isArchivedRoom; // Skip if we aren't including multiple participant reports and this report has multiple participants - if (!isCurrentUserOwnedPolicyExpenseChatThatCouldShow && !includeMultipleParticipantReports && !reportOption.login) { + if (!isCurrentUserOwnedPolicyExpenseChatThatCouldShow && !includeMultipleParticipantReports && !reportOption.accountID) { continue; } // If we're excluding threads, check the report to see if it has a single participant and if the participant is already selected - if (!includeThreads && reportOption.login && _.some(loginOptionsToExclude, (option) => option.login === reportOption.login)) { + if (!includeThreads && reportOption.accountID && _.some(accountIDOptionsToExclude, (option) => option.accountID === reportOption.accountID)) { continue; } @@ -719,9 +722,9 @@ function getOptions( recentReportOptions.push(reportOption); - // Add this login to the exclude list so it won't appear when we process the personal details - if (reportOption.login) { - loginOptionsToExclude.push({login: reportOption.login}); + // Add this accountID to the exclude list, so it won't appear when we process the personal details + if (reportOption.accountID) { + accountIDOptionsToExclude.push({accountID: reportOption.accountID}); } } } @@ -729,7 +732,7 @@ function getOptions( if (includePersonalDetails) { // Next loop over all personal details removing any that are selectedUsers or recentChats _.each(allPersonalDetailsOptions, (personalDetailOption) => { - if (_.some(loginOptionsToExclude, (loginOptionToExclude) => loginOptionToExclude.login === personalDetailOption.login)) { + if (_.some(accountIDOptionsToExclude, (accountIDOptionToExclude) => accountIDOptionToExclude.accountID === personalDetailOption.accountID)) { return; } const {searchText, participantsList, isChatRoom} = personalDetailOption; @@ -741,22 +744,21 @@ function getOptions( }); } - let currentUserOption = _.find(allPersonalDetailsOptions, (personalDetailsOption) => personalDetailsOption.login === currentUserLogin); + let currentUserOption = _.find(allPersonalDetailsOptions, (personalDetailsOption) => personalDetailsOption.accountID === currentUserAccountID); if (searchValue && !isSearchStringMatch(searchValue, currentUserOption.searchText)) { currentUserOption = null; } let userToInvite = null; const noOptions = recentReportOptions.length + personalDetailsOptions.length === 0 && !currentUserOption; - const noOptionsMatchExactly = !_.find(personalDetailsOptions.concat(recentReportOptions), (option) => option.login === searchValue.toLowerCase()); - + const noOptionsMatchExactly = !_.find(personalDetailsOptions.concat(recentReportOptions), (option) => (option.login || option.searchText) === searchValue.toLowerCase()); if ( searchValue && (noOptions || noOptionsMatchExactly) && !isCurrentUser({login: searchValue}) && _.every(selectedOptions, (option) => option.login !== searchValue) && ((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue)) || parsedPhoneNumber.possible) && - !_.find(loginOptionsToExclude, (loginOptionToExclude) => loginOptionToExclude.login === addSMSDomainIfPhoneNumber(searchValue).toLowerCase()) && + // TODO: reference accountIDOptionsToExclude here too - maybe search through personalDetails for searchValue? (searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas)) ) { // Generates an optimistic account ID for new users not yet saved in Onyx