Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invoice thread opens when starting DM with the user after sending invoice to them #45500

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
17 changes: 7 additions & 10 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5562,16 +5562,13 @@ function getChatByParticipants(newParticipantList: number[], reports: OnyxCollec
return Object.values(reports ?? {}).find((report) => {
const participantAccountIDs = Object.keys(report?.participants ?? {});

// If the report has been deleted, or there are no participants (like an empty #admins room) then skip it
if (
participantAccountIDs.length === 0 ||
isChatThread(report) ||
isTaskReport(report) ||
isMoneyRequestReport(report) ||
isChatRoom(report) ||
isPolicyExpenseChat(report) ||
(isGroupChat(report) && !shouldIncludeGroupChats)
) {
// Skip if it's not a 1:1 chat
if (!shouldIncludeGroupChats && !isOneOnOneChat(report)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is isOneOnOneChat or isDM more relevant in our case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe isOneOnOneChat.

return false;
}

// If we are looking for a group chat, then skip non-group chat report
if (shouldIncludeGroupChats && !isGroupChat(report)) {
return false;
}

Expand Down
56 changes: 56 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,4 +970,60 @@ describe('ReportUtils', () => {
expect(ReportUtils.isChatUsedForOnboarding(report2)).toBeFalsy();
});
});

describe('getChatByParticipants', () => {
const userAccountID = 1;
const userAccountID2 = 2;
let oneOnOneChatReport: Report;
let groupChatReport: Report;

beforeAll(() => {
const invoiceReport: Report = {
reportID: '1',
type: CONST.REPORT.TYPE.INVOICE,
participants: {[userAccountID]: {hidden: false}, [currentUserAccountID]: {hidden: false}},
};
const taskReport: Report = {
reportID: '2',
type: CONST.REPORT.TYPE.TASK,
participants: {[userAccountID]: {hidden: false}, [currentUserAccountID]: {hidden: false}},
};
const iouReport: Report = {
reportID: '3',
type: CONST.REPORT.TYPE.IOU,
participants: {[userAccountID]: {hidden: false}, [currentUserAccountID]: {hidden: false}},
};
groupChatReport = {
reportID: '4',
type: CONST.REPORT.TYPE.CHAT,
chatType: CONST.REPORT.CHAT_TYPE.GROUP,
participants: {[userAccountID]: {hidden: false}, [userAccountID2]: {hidden: false}, [currentUserAccountID]: {hidden: false}},
};
oneOnOneChatReport = {
reportID: '5',
type: CONST.REPORT.TYPE.CHAT,
participants: {[userAccountID]: {hidden: false}, [currentUserAccountID]: {hidden: false}},
};
const reportCollectionDataSet = toCollectionDataSet(
ONYXKEYS.COLLECTION.REPORT,
[invoiceReport, taskReport, iouReport, groupChatReport, oneOnOneChatReport],
(item) => item.reportID,
);
return Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, reportCollectionDataSet);
});
it('should return the 1:1 chat', () => {
const report = ReportUtils.getChatByParticipants([currentUserAccountID, userAccountID]);
expect(report?.reportID).toEqual(oneOnOneChatReport.reportID);
});

it('should return the group chat', () => {
const report = ReportUtils.getChatByParticipants([currentUserAccountID, userAccountID, userAccountID2], undefined, true);
expect(report?.reportID).toEqual(groupChatReport.reportID);
});

it('should return undefined when no report is found', () => {
const report = ReportUtils.getChatByParticipants([currentUserAccountID, userAccountID2], undefined);
expect(report).toEqual(undefined);
});
});
});
Loading