diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 4c93c65b0d09..66f8912d0b5e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -358,6 +358,8 @@ function getOptions(reports, personalDetails, activeReportID, { includeRecentReports = false, prioritizePinnedReports = false, prioritizeDefaultRoomsInSearch = false, + + // When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well. sortByReportTypeInSearch = false, sortByLastMessageTimestamp = false, searchValue = '', @@ -371,7 +373,7 @@ function getOptions(reports, personalDetails, activeReportID, { }) { let recentReportOptions = []; const pinnedReportOptions = []; - const personalDetailsOptions = []; + let personalDetailsOptions = []; const iouDebtReportOptions = []; const draftReportOptions = []; @@ -383,7 +385,10 @@ function getOptions(reports, personalDetails, activeReportID, { sortProperty = ['reportName']; } const sortDirection = [sortByAlphaAsc ? 'asc' : 'desc']; - const orderedReports = lodashOrderBy(reports, sortProperty, sortDirection); + let orderedReports = lodashOrderBy(reports, sortProperty, sortDirection); + + // Move the archived Rooms to the last + orderedReports = _.sortBy(orderedReports, report => ReportUtils.isArchivedRoom(report)); const allReportOptions = []; _.each(orderedReports, (report) => { @@ -513,19 +518,6 @@ function getOptions(reports, personalDetails, activeReportID, { recentReportOptions = reportsSplitByDefaultChatRoom[0].concat(reportsSplitByDefaultChatRoom[1]); } - // If we are prioritizing 1:1 chats in search, do it only once we started searching - if (sortByReportTypeInSearch && searchValue !== '') { - recentReportOptions = lodashOrderBy(recentReportOptions, [(option) => { - if (option.isChatRoom || option.isArchivedRoom) { - return 3; - } - if (!option.login) { - return 2; - } - return 1; - }], ['asc']); - } - if (includePersonalDetails) { // Next loop over all personal details removing any that are selectedUsers or recentChats _.each(allPersonalDetailsOptions, (personalDetailOption) => { @@ -565,6 +557,22 @@ function getOptions(reports, personalDetails, activeReportID, { userToInvite.icons = [defaultAvatarForUserToInvite]; } + // If we are prioritizing 1:1 chats in search, do it only once we started searching + if (sortByReportTypeInSearch && searchValue !== '') { + // When sortByReportTypeInSearch is true, recentReports will be returned with all the reports including personalDetailsOptions in the correct Order. + recentReportOptions.push(...personalDetailsOptions); + personalDetailsOptions = []; + recentReportOptions = lodashOrderBy(recentReportOptions, [(option) => { + if (option.isChatRoom || option.isArchivedRoom) { + return 3; + } + if (!option.login) { + return 2; + } + return 1; + }], ['asc']); + } + return { personalDetails: personalDetailsOptions, recentReports: recentReportOptions, diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 664af9ad0415..1fc76da9c3be 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -90,12 +90,18 @@ class SearchPage extends Component { * @returns {Array} */ getSections() { - const sections = [{ - title: this.props.translate('common.recents'), - data: this.state.recentReports.concat(this.state.personalDetails), - shouldShow: true, - indexOffset: 0, - }]; + const sections = [ + { + data: this.state.recentReports, + shouldShow: true, + indexOffset: 0, + }, + { + data: this.state.personalDetails, + shouldShow: true, + indexOffset: this.state.recentReports.length, + }, + ]; if (this.state.userToInvite) { sections.push(({ @@ -169,16 +175,16 @@ class SearchPage extends Component { {didScreenTransitionEnd && ( - + )}