@@ -6135,23 +6135,41 @@ function isWorkspaceChat(chatType: string) {
6135
6135
/**
6136
6136
* Builds an optimistic chat report with a randomly generated reportID and as much information as we currently have
6137
6137
*/
6138
- function buildOptimisticChatReport (
6139
- participantList : number [ ] ,
6140
- reportName : string = CONST . REPORT . DEFAULT_REPORT_NAME ,
6141
- chatType ?: ValueOf < typeof CONST . REPORT . CHAT_TYPE > ,
6142
- policyID : string = CONST . POLICY . OWNER_EMAIL_FAKE ,
6143
- ownerAccountID : number = CONST . REPORT . OWNER_ACCOUNT_ID_FAKE ,
6138
+ type BuildOptimisticChatReportParams = {
6139
+ participantList : number [ ] ;
6140
+ reportName ?: string ;
6141
+ chatType ?: ValueOf < typeof CONST . REPORT . CHAT_TYPE > ;
6142
+ policyID ?: string ;
6143
+ ownerAccountID ?: number ;
6144
+ isOwnPolicyExpenseChat ?: boolean ;
6145
+ oldPolicyName ?: string ;
6146
+ visibility ?: ValueOf < typeof CONST . REPORT . VISIBILITY > ;
6147
+ writeCapability ?: ValueOf < typeof CONST . REPORT . WRITE_CAPABILITIES > ;
6148
+ notificationPreference ?: NotificationPreference ;
6149
+ parentReportActionID ?: string ;
6150
+ parentReportID ?: string ;
6151
+ description ?: string ;
6152
+ avatarUrl ?: string ;
6153
+ optimisticReportID ?: string ;
6154
+ } ;
6155
+
6156
+ function buildOptimisticChatReport ( {
6157
+ participantList,
6158
+ reportName = CONST . REPORT . DEFAULT_REPORT_NAME ,
6159
+ chatType,
6160
+ policyID = CONST . POLICY . OWNER_EMAIL_FAKE ,
6161
+ ownerAccountID = CONST . REPORT . OWNER_ACCOUNT_ID_FAKE ,
6144
6162
isOwnPolicyExpenseChat = false ,
6145
6163
oldPolicyName = '' ,
6146
- visibility ?: ValueOf < typeof CONST . REPORT . VISIBILITY > ,
6147
- writeCapability ?: ValueOf < typeof CONST . REPORT . WRITE_CAPABILITIES > ,
6148
- notificationPreference : NotificationPreference = CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS ,
6164
+ visibility,
6165
+ writeCapability,
6166
+ notificationPreference = CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS ,
6149
6167
parentReportActionID = '' ,
6150
6168
parentReportID = '' ,
6151
6169
description = '' ,
6152
6170
avatarUrl = '' ,
6153
6171
optimisticReportID = '' ,
6154
- ) : OptimisticChatReport {
6172
+ } : BuildOptimisticChatReportParams ) : OptimisticChatReport {
6155
6173
const isWorkspaceChatType = chatType && isWorkspaceChat ( chatType ) ;
6156
6174
const participants = participantList . reduce ( ( reportParticipants : Participants , accountID : number ) => {
6157
6175
const participant : ReportParticipant = {
@@ -6207,23 +6225,14 @@ function buildOptimisticGroupChatReport(
6207
6225
optimisticReportID ?: string ,
6208
6226
notificationPreference ?: NotificationPreference ,
6209
6227
) {
6210
- return buildOptimisticChatReport (
6211
- participantAccountIDs ,
6228
+ return buildOptimisticChatReport ( {
6229
+ participantList : participantAccountIDs ,
6212
6230
reportName,
6213
- CONST . REPORT . CHAT_TYPE . GROUP ,
6214
- undefined ,
6215
- undefined ,
6216
- undefined ,
6217
- undefined ,
6218
- undefined ,
6219
- undefined ,
6231
+ chatType : CONST . REPORT . CHAT_TYPE . GROUP ,
6220
6232
notificationPreference,
6221
- undefined ,
6222
- undefined ,
6223
- undefined ,
6224
- avatarUri ,
6233
+ avatarUrl : avatarUri ,
6225
6234
optimisticReportID,
6226
- ) ;
6235
+ } ) ;
6227
6236
}
6228
6237
6229
6238
/**
@@ -6623,18 +6632,17 @@ function buildOptimisticAnnounceChat(policyID: string, accountIDs: number[]): Op
6623
6632
} ;
6624
6633
}
6625
6634
6626
- const announceChatData = buildOptimisticChatReport (
6627
- accountIDs ,
6628
- CONST . REPORT . WORKSPACE_CHAT_ROOMS . ANNOUNCE ,
6629
- CONST . REPORT . CHAT_TYPE . POLICY_ANNOUNCE ,
6635
+ const announceChatData = buildOptimisticChatReport ( {
6636
+ participantList : accountIDs ,
6637
+ reportName : CONST . REPORT . WORKSPACE_CHAT_ROOMS . ANNOUNCE ,
6638
+ chatType : CONST . REPORT . CHAT_TYPE . POLICY_ANNOUNCE ,
6630
6639
policyID,
6631
- CONST . POLICY . OWNER_ACCOUNT_ID_FAKE ,
6632
- false ,
6633
- policy ?. name ,
6634
- undefined ,
6635
- CONST . REPORT . WRITE_CAPABILITIES . ADMINS ,
6636
- CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS ,
6637
- ) ;
6640
+ ownerAccountID : CONST . POLICY . OWNER_ACCOUNT_ID_FAKE ,
6641
+ oldPolicyName : policy ?. name ,
6642
+ writeCapability : CONST . REPORT . WRITE_CAPABILITIES . ADMINS ,
6643
+ notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS ,
6644
+ } ) ;
6645
+
6638
6646
const announceCreatedAction = buildOptimisticCreatedReportAction ( CONST . POLICY . OWNER_EMAIL_FAKE ) ;
6639
6647
announceRoomOnyxData . onyxOptimisticData . push (
6640
6648
{
@@ -6726,39 +6734,32 @@ function buildOptimisticAnnounceChat(policyID: string, accountIDs: number[]): Op
6726
6734
function buildOptimisticWorkspaceChats ( policyID : string , policyName : string , expenseReportId ?: string ) : OptimisticWorkspaceChats {
6727
6735
const pendingChatMembers = getPendingChatMembers ( currentUserAccountID ? [ currentUserAccountID ] : [ ] , [ ] , CONST . RED_BRICK_ROAD_PENDING_ACTION . ADD ) ;
6728
6736
const adminsChatData = {
6729
- ...buildOptimisticChatReport (
6730
- currentUserAccountID ? [ currentUserAccountID ] : [ ] ,
6731
- CONST . REPORT . WORKSPACE_CHAT_ROOMS . ADMINS ,
6732
- CONST . REPORT . CHAT_TYPE . POLICY_ADMINS ,
6737
+ ...buildOptimisticChatReport ( {
6738
+ participantList : currentUserAccountID ? [ currentUserAccountID ] : [ ] ,
6739
+ reportName : CONST . REPORT . WORKSPACE_CHAT_ROOMS . ADMINS ,
6740
+ chatType : CONST . REPORT . CHAT_TYPE . POLICY_ADMINS ,
6733
6741
policyID,
6734
- CONST . POLICY . OWNER_ACCOUNT_ID_FAKE ,
6735
- false ,
6736
- policyName ,
6737
- ) ,
6742
+ ownerAccountID : CONST . POLICY . OWNER_ACCOUNT_ID_FAKE ,
6743
+ oldPolicyName : policyName ,
6744
+ } ) ,
6738
6745
} ;
6739
6746
const adminsChatReportID = adminsChatData . reportID ;
6740
6747
const adminsCreatedAction = buildOptimisticCreatedReportAction ( CONST . POLICY . OWNER_EMAIL_FAKE ) ;
6741
6748
const adminsReportActionData = {
6742
6749
[ adminsCreatedAction . reportActionID ] : adminsCreatedAction ,
6743
6750
} ;
6744
6751
6745
- const expenseChatData = buildOptimisticChatReport (
6746
- currentUserAccountID ? [ currentUserAccountID ] : [ ] ,
6747
- '' ,
6748
- CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ,
6752
+ const expenseChatData = buildOptimisticChatReport ( {
6753
+ participantList : currentUserAccountID ? [ currentUserAccountID ] : [ ] ,
6754
+ reportName : '' ,
6755
+ chatType : CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ,
6749
6756
policyID,
6750
- currentUserAccountID ,
6751
- true ,
6752
- policyName ,
6753
- undefined ,
6754
- undefined ,
6755
- undefined ,
6756
- undefined ,
6757
- undefined ,
6758
- undefined ,
6759
- undefined ,
6760
- expenseReportId ,
6761
- ) ;
6757
+ ownerAccountID : currentUserAccountID ,
6758
+ isOwnPolicyExpenseChat : true ,
6759
+ oldPolicyName : policyName ,
6760
+ optimisticReportID : expenseReportId ,
6761
+ } ) ;
6762
+
6762
6763
const expenseChatReportID = expenseChatData . reportID ;
6763
6764
const expenseReportCreatedAction = buildOptimisticCreatedReportAction ( currentUserEmail ?? '' ) ;
6764
6765
const expenseReportActionData = {
@@ -6884,20 +6885,15 @@ function buildTransactionThread(
6884
6885
} ;
6885
6886
}
6886
6887
6887
- return buildOptimisticChatReport (
6888
- participantAccountIDs ,
6889
- getTransactionReportName ( { reportAction} ) ,
6890
- undefined ,
6891
- moneyRequestReport ?. policyID ,
6892
- CONST . POLICY . OWNER_ACCOUNT_ID_FAKE ,
6893
- false ,
6894
- '' ,
6895
- undefined ,
6896
- undefined ,
6897
- CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
6898
- reportAction ?. reportActionID ,
6899
- moneyRequestReport ?. reportID ,
6900
- ) ;
6888
+ return buildOptimisticChatReport ( {
6889
+ participantList : participantAccountIDs ,
6890
+ reportName : getTransactionReportName ( { reportAction} ) ,
6891
+ policyID : moneyRequestReport ?. policyID ,
6892
+ ownerAccountID : CONST . POLICY . OWNER_ACCOUNT_ID_FAKE ,
6893
+ notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
6894
+ parentReportActionID : reportAction ?. reportActionID ,
6895
+ parentReportID : moneyRequestReport ?. reportID ,
6896
+ } ) ;
6901
6897
}
6902
6898
6903
6899
/**
0 commit comments