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 - Split bill - New group is created when splitting bill with the same users #42444

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
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5501,7 +5501,7 @@ function getSystemChat(): OnyxEntry<Report> {
/**
* Attempts to find a report in onyx with the provided list of participants. Does not include threads, task, expense, room, and policy expense chat.
*/
function getChatByParticipants(newParticipantList: number[], reports: OnyxCollection<Report> = allReports): OnyxEntry<Report> {
function getChatByParticipants(newParticipantList: number[], reports: OnyxCollection<Report> = allReports, shouldIncludeGroupChats = false): OnyxEntry<Report> {
const sortedNewParticipantList = newParticipantList.sort();
return Object.values(reports ?? {}).find((report) => {
const participantAccountIDs = Object.keys(report?.participants ?? {});
Expand All @@ -5514,7 +5514,7 @@ function getChatByParticipants(newParticipantList: number[], reports: OnyxCollec
isMoneyRequestReport(report) ||
isChatRoom(report) ||
isPolicyExpenseChat(report) ||
isGroupChat(report)
(isGroupChat(report) && !shouldIncludeGroupChats)
) {
return false;
}
Expand Down
6 changes: 2 additions & 4 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3776,11 +3776,9 @@ function getOrCreateOptimisticSplitChatReport(existingSplitChatReportID: string,
// Check if the report is available locally if we do have one
let existingSplitChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${existingChatReportID}`];

// If we do not have one locally then we will search for a chat with the same participants (only for 1:1 chats).
const shouldGetOrCreateOneOneDM = participants.length < 2;
const allParticipantsAccountIDs = [...participantAccountIDs, currentUserAccountID];
if (!existingSplitChatReport && shouldGetOrCreateOneOneDM) {
existingSplitChatReport = ReportUtils.getChatByParticipants(allParticipantsAccountIDs);
if (!existingSplitChatReport) {
existingSplitChatReport = ReportUtils.getChatByParticipants(allParticipantsAccountIDs, undefined, participantAccountIDs.length > 1);
}

// We found an existing chat report we are done...
Expand Down
Loading