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

Correctly find Worspace Expense chats when inviting users #42500

Merged
merged 9 commits into from
May 27, 2024
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
20 changes: 7 additions & 13 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5244,23 +5244,17 @@ function getInvoiceChatByParticipants(policyID: string, receiverID: string | num
}

/**
* Attempts to find a report in onyx with the provided list of participants in given policy
* Attempts to find a policy expense report in onyx that is owned by ownerAccountID in a given policy
*/
function getChatByParticipantsAndPolicy(newParticipantList: number[], policyID: string): OnyxEntry<Report> {
newParticipantList.sort();
function getPolicyExpenseChat(ownerAccountID: number, policyID: string): OnyxEntry<Report> {
return (
Object.values(allReports ?? {}).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 (!report || participantAccountIDs.length === 0) {
Object.values(allReports ?? {}).find((report: OnyxEntry<Report>) => {
// If the report has been deleted, then skip it
if (!report) {
return false;
}

const sortedParticipantsAccountIDs = participantAccountIDs.map(Number).sort();

// Only return the room if it has all the participants and is not a policy room
return report.policyID === policyID && newParticipantList.every((newParticipant) => sortedParticipantsAccountIDs.includes(newParticipant));
return report.policyID === policyID && isPolicyExpenseChat(report) && report.ownerAccountID === ownerAccountID;
}) ?? null
);
}
Expand Down Expand Up @@ -6757,7 +6751,6 @@ export {
getAvailableReportFields,
getBankAccountRoute,
getChatByParticipants,
getChatByParticipantsAndPolicy,
getChatRoomSubtitle,
getChildReportNotificationPreference,
getCommentLength,
Expand Down Expand Up @@ -6789,6 +6782,7 @@ export {
getPendingChatMembers,
getPersonalDetailsForAccountID,
getPolicyDescriptionText,
getPolicyExpenseChat,
getPolicyName,
getPolicyType,
getReimbursementDeQueuedActionMessage,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I
const cleanAccountID = Number(accountID);
const login = PhoneNumber.addSMSDomainIfPhoneNumber(email);

const oldChat = ReportUtils.getChatByParticipantsAndPolicy([sessionAccountID, cleanAccountID], policyID);
const oldChat = ReportUtils.getPolicyExpenseChat(cleanAccountID, policyID);
Gonals marked this conversation as resolved.
Show resolved Hide resolved

// If the chat already exists, we don't want to create a new one - just make sure it's not archived
if (oldChat) {
Expand Down
Loading