Skip to content

Commit

Permalink
Merge pull request #8476 from Expensify/amal-workspace-chat-lhn
Browse files Browse the repository at this point in the history
Show empty policyExpenseChats in LHN just like defaultRooms
  • Loading branch information
neil-marcellini authored Apr 18, 2022
2 parents 6c53be1 + 156d7af commit 88a03ff
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 !== '';
Expand Down
98 changes: 98 additions & 0 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 88a03ff

Please sign in to comment.