@@ -5245,23 +5245,17 @@ function getInvoiceChatByParticipants(policyID: string, receiverID: string | num
5245
5245
}
5246
5246
5247
5247
/**
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
5249
5249
*/
5250
- function getChatByParticipantsAndPolicy ( newParticipantList : number [ ] , policyID : string ) : OnyxEntry < Report > {
5251
- newParticipantList . sort ( ) ;
5250
+ function getPolicyExpenseChat ( ownerAccountID : number , policyID : string ) : OnyxEntry < Report > {
5252
5251
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 ) {
5258
5255
return false ;
5259
5256
}
5260
5257
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 ;
5265
5259
} ) ?? null
5266
5260
) ;
5267
5261
}
@@ -6758,7 +6752,6 @@ export {
6758
6752
getAvailableReportFields ,
6759
6753
getBankAccountRoute ,
6760
6754
getChatByParticipants ,
6761
- getChatByParticipantsAndPolicy ,
6762
6755
getChatRoomSubtitle ,
6763
6756
getChildReportNotificationPreference ,
6764
6757
getCommentLength ,
@@ -6790,6 +6783,7 @@ export {
6790
6783
getPendingChatMembers ,
6791
6784
getPersonalDetailsForAccountID ,
6792
6785
getPolicyDescriptionText ,
6786
+ getPolicyExpenseChat ,
6793
6787
getPolicyName ,
6794
6788
getPolicyType ,
6795
6789
getReimbursementDeQueuedActionMessage ,
0 commit comments