Skip to content

Commit dd454ba

Browse files
authored
Merge pull request #42500 from Expensify/alberto-policyChat
Correctly find Worspace Expense chats when inviting users
2 parents 13772bd + 5fe21ab commit dd454ba

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/libs/ReportUtils.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -5245,23 +5245,17 @@ function getInvoiceChatByParticipants(policyID: string, receiverID: string | num
52455245
}
52465246

52475247
/**
5248-
* Attempts to find a report in onyx with the provided list of participants in given policy
5248+
* Attempts to find a policy expense report in onyx that is owned by ownerAccountID in a given policy
52495249
*/
5250-
function getChatByParticipantsAndPolicy(newParticipantList: number[], policyID: string): OnyxEntry<Report> {
5251-
newParticipantList.sort();
5250+
function getPolicyExpenseChat(ownerAccountID: number, policyID: string): OnyxEntry<Report> {
52525251
return (
5253-
Object.values(allReports ?? {}).find((report) => {
5254-
const participantAccountIDs = Object.keys(report?.participants ?? {});
5255-
5256-
// If the report has been deleted, or there are no participants (like an empty #admins room) then skip it
5257-
if (!report || participantAccountIDs.length === 0) {
5252+
Object.values(allReports ?? {}).find((report: OnyxEntry<Report>) => {
5253+
// If the report has been deleted, then skip it
5254+
if (!report) {
52585255
return false;
52595256
}
52605257

5261-
const sortedParticipantsAccountIDs = participantAccountIDs.map(Number).sort();
5262-
5263-
// Only return the room if it has all the participants and is not a policy room
5264-
return report.policyID === policyID && newParticipantList.every((newParticipant) => sortedParticipantsAccountIDs.includes(newParticipant));
5258+
return report.policyID === policyID && isPolicyExpenseChat(report) && report.ownerAccountID === ownerAccountID;
52655259
}) ?? null
52665260
);
52675261
}
@@ -6758,7 +6752,6 @@ export {
67586752
getAvailableReportFields,
67596753
getBankAccountRoute,
67606754
getChatByParticipants,
6761-
getChatByParticipantsAndPolicy,
67626755
getChatRoomSubtitle,
67636756
getChildReportNotificationPreference,
67646757
getCommentLength,
@@ -6790,6 +6783,7 @@ export {
67906783
getPendingChatMembers,
67916784
getPersonalDetailsForAccountID,
67926785
getPolicyDescriptionText,
6786+
getPolicyExpenseChat,
67936787
getPolicyName,
67946788
getPolicyType,
67956789
getReimbursementDeQueuedActionMessage,

src/libs/actions/Policy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I
13061306
const cleanAccountID = Number(accountID);
13071307
const login = PhoneNumber.addSMSDomainIfPhoneNumber(email);
13081308

1309-
const oldChat = ReportUtils.getChatByParticipantsAndPolicy([sessionAccountID, cleanAccountID], policyID);
1309+
const oldChat = ReportUtils.getPolicyExpenseChat(cleanAccountID, policyID);
13101310

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

0 commit comments

Comments
 (0)