Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ type OptimisticExpenseReport = Pick<
| 'parentReportActionID'
| 'participants'
| 'fieldList'
| 'transactionCount'
>;

type OptimisticNewReport = Pick<
Expand Down Expand Up @@ -7281,6 +7282,7 @@ function buildOptimisticInvoiceReport(
parentReportID: chatReportID,
created,
lastVisibleActionCreated: created,
transactionCount: 1,
};

if (deprecatedCurrentUserAccountID) {
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading