Skip to content

Commit

Permalink
Merge pull request #3847 from Expensify/amal-default-rooms-no-partici…
Browse files Browse the repository at this point in the history
…pants

Fix particpant related and searching behavior for default rooms.
  • Loading branch information
HorusGoul authored Jul 5, 2021
2 parents 079c12b + 998a741 commit 045b394
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -456,6 +472,7 @@ function getSearchOptions(
includeMultipleParticipantReports: true,
maxRecentReportsToShow: 0, // Unlimited
prioritizePinnedReports: false,
prioritizeDefaultRoomsInSearch: true,
showChatPreviewLine: true,
showReportsWithNoComments: true,
includePersonalDetails: true,
Expand Down Expand Up @@ -484,6 +501,7 @@ function getNewChatOptions(
return getOptions(reports, personalDetails, {}, 0, {
betas,
searchValue,
excludeDefaultRooms: true,
includePersonalDetails: true,
includeRecentReports: true,
maxRecentReportsToShow: 5,
Expand Down Expand Up @@ -545,6 +563,7 @@ function getNewGroupOptions(
betas,
searchValue,
selectedOptions,
excludeDefaultRooms: true,
includeRecentReports: true,
includePersonalDetails: true,
includeMultipleParticipantReports: false,
Expand Down

0 comments on commit 045b394

Please sign in to comment.