Skip to content

Commit

Permalink
Merge pull request #42444 from FitseTLT/fix-split-always-creating-new…
Browse files Browse the repository at this point in the history
…-group-chat-report

Fix - Split bill - New group is created when splitting bill with the same users
  • Loading branch information
youssef-lr authored Jun 26, 2024
2 parents ee7055d + 08c36bf commit aecc38b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5523,7 +5523,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 @@ -5536,7 +5536,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

0 comments on commit aecc38b

Please sign in to comment.