diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 3722b243d21c..cb8f1df50891 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -400,7 +400,13 @@ function getOptions(reports, personalDetails, activeReportID, { : ''; const reportContainsIOUDebt = iouReportOwner && iouReportOwner !== currentUserLogin; - const shouldFilterReportIfEmpty = !showReportsWithNoComments && report.lastMessageTimestamp === 0 && !isDefaultRoom; + const shouldFilterReportIfEmpty = !showReportsWithNoComments && report.lastMessageTimestamp === 0 + + // We make exceptions for defaultRooms and policyExpenseChats so we can immediately + // highlight them in the LHN when they are created and have no messsages yet. We do + // not give archived rooms this exception since they do not need to be higlihted. + && !(!ReportUtils.isArchivedRoom(report) && (isDefaultRoom || isPolicyExpenseChat)); + const shouldFilterReportIfRead = hideReadReports && report.unreadActionCount === 0; const shouldFilterReport = shouldFilterReportIfEmpty || shouldFilterReportIfRead; if (report.reportID !== activeReportID @@ -426,7 +432,7 @@ function getOptions(reports, personalDetails, activeReportID, { // Save the report in the map if this is a single participant so we can associate the reportID with the // personal detail option later. Individuals should not be associated with single participant // policyExpenseChats or chatRooms since those are not people. - if (logins.length <= 1 && !ReportUtils.isPolicyExpenseChat(report) && !ReportUtils.isChatRoom(report)) { + if (logins.length <= 1 && !isPolicyExpenseChat && !isChatRoom) { reportMapForLogins[logins[0]] = report; } const isSearchingSomeonesPolicyExpenseChat = !report.isOwnPolicyExpenseChat && searchValue !== ''; diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 15a9a7978304..3fb6441c6602 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -675,4 +675,102 @@ describe('OptionsListUtils', () => { // Spider-Man report name is last report and has unread message expect(results.recentReports[8].login).toBe('peterparker@expensify.com'); })); + + it('getSidebarOptions() with empty policyExpenseChats and defaultRooms', () => { + const reportsWithEmptyChatRooms = { + // This report is a policyExpenseChat without any messages in it (i.e. no lastMessageTimestamp) + 10: { + chatType: 'policyExpenseChat', + hasOutstandingIOU: false, + isOwnPolicyExpenseChat: true, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: 'Whatever', + reportID: 10, + reportName: "Someone's workspace", + unreadActionCount: 0, + visibility: undefined, + }, + + // This is an archived version of the above policyExpenseChat + 11: { + chatType: 'policyExpenseChat', + hasOutstandingIOU: false, + isOwnPolicyExpenseChat: true, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: 'Whatever', + reportID: 11, + reportName: "Someone's workspace", + unreadActionCount: 0, + visibility: undefined, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS.CLOSED, + }, + + // This report is a defaultRoom without any messages in it (i.e. no lastMessageTimestamp) + 12: { + chatType: 'policyAdmins', + hasOutstandingIOU: false, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: 'Whatever', + reportID: 12, + reportName: '#admins', + unreadActionCount: 0, + visibility: undefined, + }, + + // This is an archived version of the above defaultRoom + 13: { + chatType: 'policyAdmins', + hasOutstandingIOU: false, + isPinned: false, + lastMessageTimestamp: 0, + lastVisitedTimestamp: 1610666739302, + participants: ['test3@instantworkspace.com'], + policyID: 'Whatever', + reportID: 13, + reportName: '#admins', + unreadActionCount: 0, + visibility: undefined, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS.CLOSED, + }, + }; + + // First we call getSidebarOptions() with no search value and default priority mode + let results = OptionsListUtils.getSidebarOptions( + reportsWithEmptyChatRooms, + PERSONAL_DETAILS, + 0, + CONST.PRIORITY_MODE.DEFAULT, + ); + + // Then expect all of the reports to be shown except the archived policyExpenseChats and defaultRooms + expect(results.recentReports.length).toBe(_.size(reportsWithEmptyChatRooms) - 2); + + expect(results.recentReports[0].isPolicyExpenseChat).toBe(true); + expect(results.recentReports[0].text).toBe("Someone's workspace"); + + expect(results.recentReports[1].isChatRoom).toBe(true); + expect(results.recentReports[1].text).toBe('#admins'); + + // Now we call getSidebarOptions() with no search value and GSD priority mode + results = OptionsListUtils.getSidebarOptions( + reportsWithEmptyChatRooms, + PERSONAL_DETAILS, + 0, + CONST.PRIORITY_MODE.GSD, + ); + + // None of the chats should be here since they've all been read + expect(results.recentReports.length).toBe(0); + }); });