Skip to content

Commit

Permalink
Migrate to accountID & simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Beamanator committed Jun 7, 2023
1 parent dda26cb commit 5bd48f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1730,11 +1730,10 @@ function isUnreadWithMention(report) {
*
* @param {Object} report
* @param {String} report.iouReportID
* @param {String} currentUserLogin
* @param {Object} iouReports
* @returns {boolean}
*/
function hasOutstandingIOU(report, currentUserLogin, iouReports) {
function hasOutstandingIOU(report, iouReports) {
if (!report || !report.iouReportID || _.isUndefined(report.hasOutstandingIOU)) {
return false;
}
Expand Down Expand Up @@ -1816,13 +1815,12 @@ function canSeeDefaultRoom(report, policies, betas) {
* @param {Object} report
* @param {String} reportIDFromRoute
* @param {Boolean} isInGSDMode
* @param {String} currentUserLogin
* @param {Object} iouReports
* @param {String[]} betas
* @param {Object} policies
* @returns {boolean}
*/
function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, iouReports, betas, policies) {
function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, iouReports, betas, policies) {

This comment has been minimized.

Copy link
@fedirjh

fedirjh Jul 5, 2023

Contributor

This change introduced a regression in #21313, We should have updated all instances where shouldReportBeInOptionList is used, because it will pass an invalid number of arguments.

const isInDefaultMode = !isInGSDMode;

// Exclude reports that have no data because there wouldn't be anything to show in the option item.
Expand All @@ -1849,7 +1847,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr

// Include reports if they have a draft, are pinned, or have an outstanding IOU
// These are always relevant to the user no matter what view mode the user prefers
if (report.hasDraft || report.isPinned || hasOutstandingIOU(report, currentUserLogin, iouReports)) {
if (report.hasDraft || report.isPinned || hasOutstandingIOU(report, iouReports)) {
return true;
}

Expand Down
10 changes: 6 additions & 4 deletions src/libs/SidebarUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ Onyx.connect({
callback: (val) => (policies = val),
});

let currentUserLogin;
let currentUserAccountID;
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => (currentUserLogin = val),
callback: (val) => {
currentUserAccountID = val.accountID;
},
});

let preferredLocale;
Expand All @@ -99,7 +101,7 @@ function getOrderedReportIDs(reportIDFromRoute) {
const isInDefaultMode = !isInGSDMode;

// Filter out all the reports that shouldn't be displayed
const reportsToDisplay = _.filter(allReports, (report) => ReportUtils.shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, currentUserLogin, allReports, betas, policies));
const reportsToDisplay = _.filter(allReports, (report) => ReportUtils.shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, allReports, betas, policies));
if (_.isEmpty(reportsToDisplay)) {
// Display Concierge chat report when there is no report to be displayed
const conciergeChatReport = _.find(allReports, ReportUtils.isConciergeChatReport);
Expand Down Expand Up @@ -286,7 +288,7 @@ function getOptionData(reportID) {
}
: null;
}
let lastMessageText = hasMultipleParticipants && lastActorDetails && lastActorDetails.login !== currentUserLogin.email ? `${lastActorDetails.displayName}: ` : '';
let lastMessageText = hasMultipleParticipants && lastActorDetails && lastActorDetails.accountID !== currentUserAccountID ? `${lastActorDetails.displayName}: ` : '';
lastMessageText += report ? lastMessageTextFromReport : '';

if (result.isArchivedRoom) {
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/ReportUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ describe('ReportUtils', () => {
iouReportID: '1',
};
const iouReports = {};
expect(ReportUtils.hasOutstandingIOU(report, undefined, iouReports)).toBe(false);
expect(ReportUtils.hasOutstandingIOU(report, iouReports)).toBe(false);
});
it('returns false when the matched IOU report does not have an owner email', () => {
const report = {
Expand All @@ -292,7 +292,7 @@ describe('ReportUtils', () => {
reportID: '1',
},
};
expect(ReportUtils.hasOutstandingIOU(report, undefined, iouReports)).toBe(false);
expect(ReportUtils.hasOutstandingIOU(report, iouReports)).toBe(false);
});
it('returns false when the matched IOU report does not have an owner email', () => {
const report = {
Expand All @@ -305,7 +305,7 @@ describe('ReportUtils', () => {
ownerEmail: 'a@a.com',
},
};
expect(ReportUtils.hasOutstandingIOU(report, 'b@b.com', iouReports)).toBe(false);
expect(ReportUtils.hasOutstandingIOU(report, iouReports)).toBe(false);
});
it('returns true when the report has an oustanding IOU', () => {
const report = {
Expand All @@ -319,7 +319,7 @@ describe('ReportUtils', () => {
ownerEmail: 'a@a.com',
},
};
expect(ReportUtils.hasOutstandingIOU(report, 'b@b.com', iouReports)).toBe(true);
expect(ReportUtils.hasOutstandingIOU(report, iouReports)).toBe(true);
});
it('returns false when the report has no oustanding IOU', () => {
const report = {
Expand All @@ -333,7 +333,7 @@ describe('ReportUtils', () => {
ownerEmail: 'a@a.com',
},
};
expect(ReportUtils.hasOutstandingIOU(report, 'b@b.com', iouReports)).toBe(false);
expect(ReportUtils.hasOutstandingIOU(report, iouReports)).toBe(false);
});
});

Expand Down

0 comments on commit 5bd48f8

Please sign in to comment.