diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d6f7f09e2ed3..335996f9be14 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -400,6 +400,7 @@ type OptimisticExpenseReport = Pick< | 'parentReportActionID' | 'participants' | 'fieldList' + | 'transactionCount' >; type OptimisticNewReport = Pick< @@ -7281,6 +7282,7 @@ function buildOptimisticInvoiceReport( parentReportID: chatReportID, created, lastVisibleActionCreated: created, + transactionCount: 1, }; if (deprecatedCurrentUserAccountID) { @@ -12059,7 +12061,12 @@ function canJoinChat( return false; } - const isExpenseChat = isMoneyRequestReport(report) || isMoneyRequest(report) || isInvoiceReport(report) || isTrackExpenseReportNew(report, parentReport, parentReportAction); + const isExpenseChat = + isMoneyRequestReport(report) || + isMoneyRequest(report) || + isInvoiceReport(report) || + isTrackExpenseReportNew(report, parentReport, parentReportAction) || + isInvoiceReport(parentReport); // Anyone viewing these chat types is already a participant and therefore cannot join if (isRootGroupChat(report, isReportArchived) || isSelfDM(report) || isInvoiceRoom(report) || isSystemChat(report) || isExpenseChat) { return false; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index a3e57072c218..dde91be06532 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -13164,6 +13164,26 @@ describe('ReportUtils', () => { expect(canJoinChat(report, undefined, undefined, undefined)).toBe(true); }); + it('should return false if the report is a transaction thread under an invoice report', async () => { + const parentInvoiceReport = createInvoiceReport(1); + const report: Report = { + ...createRandomReport(2, undefined), + type: CONST.REPORT.TYPE.CHAT, + participants: { + ...buildParticipantsFromAccountIDs([currentUserAccountID, 1234]), + [currentUserAccountID]: { + notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN, + }, + }, + parentReportID: parentInvoiceReport.reportID, + parentReportActionID: '67890', + }; + + await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID}); + + expect(canJoinChat(report, undefined, undefined, parentInvoiceReport)).toBe(false); + }); + it('should respect workspace membership for restricted visibility rooms', async () => { const policyID = '123456'; await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID}); @@ -17595,6 +17615,7 @@ describe('ReportUtils', () => { expect(optimisticInvoiceReport.statusNum).toBe(CONST.REPORT.STATUS_NUM.SUBMITTED); expect(optimisticInvoiceReport.stateNum).toBe(CONST.REPORT.STATE_NUM.SUBMITTED); + expect(optimisticInvoiceReport.transactionCount).toBe(1); }); it('should surface a GBR when copiloted into an approver account with a report with outstanding child request', async () => {