Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')]);
}
}
}
Expand Down Expand Up @@ -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++) {
Expand All @@ -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;
}

Expand All @@ -719,17 +722,17 @@ 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});
}
}
}

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;
Expand All @@ -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?
Comment on lines 759 to +761

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure how we'll handle this part

(searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas))
) {
// Generates an optimistic account ID for new users not yet saved in Onyx
Expand Down