Skip to content

Commit

Permalink
Merge pull request #45500 from bernhardoj/fix/45187-invoice-thread-op…
Browse files Browse the repository at this point in the history
…ens-when-selecting-chat-from-new-chat

Fix invoice thread opens when starting DM with the user after sending invoice to them
  • Loading branch information
cristipaval authored Jul 22, 2024
2 parents e3ebeff + c2bb1d3 commit 138578b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5581,16 +5581,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)) {
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 @@ -935,4 +935,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);
});
});
});

0 comments on commit 138578b

Please sign in to comment.