diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index dcd96dc4d5a5..b727b27b1b57 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -127,27 +127,35 @@ function getParticipantNames(personalDetailList) { } /** - * Returns a string with all relevant search terms + * Returns a string with all relevant search terms. + * Default should be serachable by policy name but not by participants. * * @param {Object} report * @param {Array} personalDetailList + * @param {Boolean} isDefaultChatRoom * @return {String} */ -function getSearchText(report, personalDetailList) { +function getSearchText(report, personalDetailList, isDefaultChatRoom) { const searchTerms = []; - _.each(personalDetailList, (personalDetail) => { - searchTerms.push(personalDetail.displayName); - searchTerms.push(personalDetail.login); - }); + if (!isDefaultChatRoom) { + _.each(personalDetailList, (personalDetail) => { + searchTerms.push(personalDetail.displayName); + searchTerms.push(personalDetail.login); + }); + } if (report) { searchTerms.push(...report.reportName); searchTerms.push(...report.reportName.split(',').map(name => name.trim())); - searchTerms.push(...report.participants); - // Add policy name as a search term for default rooms - if (isDefaultRoom(report) && policies[report.policyID]) { - searchTerms.push(...policies[report.policyID].name); + if (!isDefaultChatRoom) { + searchTerms.push(...report.participants); + } + + if (isDefaultChatRoom && policies[report.policyID]) { + const policyName = policies[report.policyID].name; + searchTerms.push(...policyName); + searchTerms.push(...policyName.split(',').map(name => name.trim())); } } @@ -217,7 +225,7 @@ function createOption(personalDetailList, report, draftComments, { isUnread: report ? report.unreadActionCount > 0 : null, hasDraftComment, keyForList: report ? String(report.reportID) : personalDetail.login, - searchText: getSearchText(report, personalDetailList), + searchText: getSearchText(report, personalDetailList, isDefaultChatRoom), isPinned: lodashGet(report, 'isPinned', false), hasOutstandingIOU, iouReportID: lodashGet(report, 'iouReportID'), @@ -261,10 +269,12 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { selectedOptions = [], maxRecentReportsToShow = 0, excludeConcierge = false, + excludeDefaultRooms = false, includeMultipleParticipantReports = false, includePersonalDetails = false, includeRecentReports = false, prioritizePinnedReports = false, + prioritizeDefaultRoomsInSearch = false, sortByLastMessageTimestamp = false, searchValue = '', showChatPreviewLine = false, @@ -312,7 +322,7 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { return; } - if (isDefaultRoom(report) && !Permissions.canUseDefaultRooms(betas)) { + if (isDefaultRoom(report) && (!Permissions.canUseDefaultRooms(betas) || excludeDefaultRooms)) { return; } @@ -390,6 +400,12 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, { recentReportOptions = sortedPinnedReports.concat(recentReportOptions); } + // If we are prioritizing default rooms in search, do it only once we started something + if (prioritizeDefaultRoomsInSearch && searchValue !== '') { + const reportsSplitByDefaultChatRoom = _.partition(recentReportOptions, option => option.isDefaultChatRoom); + recentReportOptions = reportsSplitByDefaultChatRoom[0].concat(reportsSplitByDefaultChatRoom[1]); + } + if (includePersonalDetails) { // Next loop over all personal details removing any that are selectedUsers or recentChats _.each(allPersonalDetailsOptions, (personalDetailOption) => { @@ -456,6 +472,7 @@ function getSearchOptions( includeMultipleParticipantReports: true, maxRecentReportsToShow: 0, // Unlimited prioritizePinnedReports: false, + prioritizeDefaultRoomsInSearch: true, showChatPreviewLine: true, showReportsWithNoComments: true, includePersonalDetails: true, @@ -484,6 +501,7 @@ function getNewChatOptions( return getOptions(reports, personalDetails, {}, 0, { betas, searchValue, + excludeDefaultRooms: true, includePersonalDetails: true, includeRecentReports: true, maxRecentReportsToShow: 5, @@ -545,6 +563,7 @@ function getNewGroupOptions( betas, searchValue, selectedOptions, + excludeDefaultRooms: true, includeRecentReports: true, includePersonalDetails: true, includeMultipleParticipantReports: false,