From 86736f7e3191c5cf36e14b125ee396647b2dec19 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 16 Jun 2023 22:32:47 +0300 Subject: [PATCH 1/4] Filter search options by accountID --- src/libs/OptionsListUtils.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index ae8da5514a28..ce98ed07d1d4 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -680,12 +680,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++) { @@ -718,9 +718,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}); } } } @@ -728,7 +728,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; @@ -748,6 +748,7 @@ function getOptions( let userToInvite = null; const noOptions = recentReportOptions.length + personalDetailsOptions.length === 0 && !currentUserOption; const noOptionsMatchExactly = !_.find(personalDetailsOptions.concat(recentReportOptions), (option) => option.login === searchValue.toLowerCase()); + console.log('NO OPTIONS', {noOptions, noOptionsMatchExactly}) if ( searchValue && @@ -755,7 +756,7 @@ function getOptions( !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 From 00b0d03cfdc1cabd087d8d1be712a8882e8ed7dd Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 16 Jun 2023 22:33:38 +0300 Subject: [PATCH 2/4] you saw nothing --- src/libs/OptionsListUtils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index ce98ed07d1d4..bc0de5528476 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -748,7 +748,6 @@ function getOptions( let userToInvite = null; const noOptions = recentReportOptions.length + personalDetailsOptions.length === 0 && !currentUserOption; const noOptionsMatchExactly = !_.find(personalDetailsOptions.concat(recentReportOptions), (option) => option.login === searchValue.toLowerCase()); - console.log('NO OPTIONS', {noOptions, noOptionsMatchExactly}) if ( searchValue && From 0478df66e11e85eb1f460cb9d0afd9fd65c4fd2a Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Fri, 16 Jun 2023 22:47:52 +0300 Subject: [PATCH 3/4] More possible fixes --- src/libs/OptionsListUtils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index bc0de5528476..37a578a6064c 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -700,12 +700,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; } From 9565f5f4068309edf0214a99eb0a29fb830524ba Mon Sep 17 00:00:00 2001 From: Monil Bhavsar Date: Tue, 20 Jun 2023 22:23:09 +0530 Subject: [PATCH 4/4] Fix logins appearing twice --- src/libs/OptionsListUtils.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index ab7edf0261ed..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, '')]); } } } @@ -719,7 +722,7 @@ function getOptions( recentReportOptions.push(reportOption); - // Add this accountID to the exclude list so it won't appear when we process the personal details + // 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}); } @@ -741,15 +744,14 @@ 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) &&