@@ -89,7 +89,6 @@ function buildOnyxDataForMoneyRequest(
89
89
reportPreviewAction ,
90
90
isNewChatReport ,
91
91
isNewIOUReport ,
92
- isNewReportPreviewAction ,
93
92
) {
94
93
const optimisticData = [
95
94
{
@@ -124,9 +123,7 @@ function buildOnyxDataForMoneyRequest(
124
123
key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ chatReport . reportID } ` ,
125
124
value : {
126
125
...( isNewChatReport ? { [ chatCreatedAction . reportActionID ] : chatCreatedAction } : { } ) ,
127
- [ reportPreviewAction . reportActionID ] : {
128
- ...( isNewReportPreviewAction ? reportPreviewAction : { created : DateUtils . getDBTime ( ) } ) ,
129
- } ,
126
+ [ reportPreviewAction . reportActionID ] : reportPreviewAction ,
130
127
} ,
131
128
} ,
132
129
{
@@ -189,13 +186,9 @@ function buildOnyxDataForMoneyRequest(
189
186
} ,
190
187
}
191
188
: { } ) ,
192
- ...( isNewReportPreviewAction
193
- ? {
194
- [ reportPreviewAction . reportActionID ] : {
195
- pendingAction : null ,
196
- } ,
197
- }
198
- : { } ) ,
189
+ [ reportPreviewAction . reportActionID ] : {
190
+ pendingAction : null ,
191
+ } ,
199
192
} ,
200
193
} ,
201
194
{
@@ -387,11 +380,14 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part
387
380
} ,
388
381
} ;
389
382
390
- let isNewReportPreviewAction = false ;
391
383
let reportPreviewAction = isNewIOUReport ? null : ReportActionsUtils . getReportPreviewAction ( chatReport . reportID , iouReport . reportID ) ;
392
- if ( ! reportPreviewAction ) {
393
- isNewReportPreviewAction = true ;
394
- reportPreviewAction = ReportUtils . buildOptimisticReportPreview ( chatReport . reportID , iouReport . reportID ) ;
384
+ if ( reportPreviewAction ) {
385
+ reportPreviewAction . created = DateUtils . getDBTime ( ) ;
386
+ const message = ReportUtils . getReportPreviewMessage ( iouReport , reportPreviewAction ) ;
387
+ reportPreviewAction . message [ 0 ] . html = message ;
388
+ reportPreviewAction . message [ 0 ] . text = message ;
389
+ } else {
390
+ reportPreviewAction = ReportUtils . buildOptimisticReportPreview ( chatReport , iouReport ) ;
395
391
}
396
392
397
393
// STEP 5: Build Onyx Data
@@ -406,7 +402,6 @@ function requestMoney(report, amount, currency, payeeEmail, payeeAccountID, part
406
402
reportPreviewAction ,
407
403
isNewChatReport ,
408
404
isNewIOUReport ,
409
- isNewReportPreviewAction ,
410
405
) ;
411
406
412
407
// STEP 6: Make the request
@@ -649,11 +644,14 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco
649
644
} ,
650
645
} ;
651
646
652
- let isNewOneOnOneReportPreviewAction = false ;
653
647
let oneOnOneReportPreviewAction = ReportActionsUtils . getReportPreviewAction ( oneOnOneChatReport . reportID , oneOnOneIOUReport . reportID ) ;
654
- if ( ! oneOnOneReportPreviewAction ) {
655
- isNewOneOnOneReportPreviewAction = true ;
656
- oneOnOneReportPreviewAction = ReportUtils . buildOptimisticReportPreview ( oneOnOneChatReport . reportID , oneOnOneIOUReport . reportID ) ;
648
+ if ( oneOnOneReportPreviewAction ) {
649
+ oneOnOneReportPreviewAction . created = DateUtils . getDBTime ( ) ;
650
+ const message = ReportUtils . getReportPreviewMessage ( oneOnOneIOUReport , oneOnOneReportPreviewAction ) ;
651
+ oneOnOneReportPreviewAction . message [ 0 ] . html = message ;
652
+ oneOnOneReportPreviewAction . message [ 0 ] . text = message ;
653
+ } else {
654
+ oneOnOneReportPreviewAction = ReportUtils . buildOptimisticReportPreview ( oneOnOneChatReport , oneOnOneIOUReport ) ;
657
655
}
658
656
659
657
// STEP 5: Build Onyx Data
@@ -668,7 +666,6 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco
668
666
oneOnOneReportPreviewAction ,
669
667
isNewOneOnOneChatReport ,
670
668
isNewOneOnOneIOUReport ,
671
- isNewOneOnOneReportPreviewAction ,
672
669
) ;
673
670
674
671
const splitData = {
@@ -944,14 +941,16 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
944
941
true ,
945
942
) ;
946
943
944
+ const reportPreviewAction = ReportUtils . buildOptimisticReportPreview ( chatReport , optimisticIOUReport ) ;
945
+
947
946
// First, add data that will be used in all cases
948
947
const optimisticChatReportData = {
949
948
onyxMethod : Onyx . METHOD . MERGE ,
950
949
key : `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReport . reportID } ` ,
951
950
value : {
952
951
...chatReport ,
953
952
lastReadTime : DateUtils . getDBTime ( ) ,
954
- lastVisibleActionCreated : optimisticIOUReportAction . created ,
953
+ lastVisibleActionCreated : reportPreviewAction . created ,
955
954
} ,
956
955
} ;
957
956
const optimisticIOUReportData = {
@@ -963,7 +962,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
963
962
lastMessageHtml : optimisticIOUReportAction . message [ 0 ] . html ,
964
963
} ,
965
964
} ;
966
- const optimisticReportActionsData = {
965
+ const optimisticIOUReportActionsData = {
967
966
onyxMethod : Onyx . METHOD . MERGE ,
968
967
key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ optimisticIOUReport . reportID } ` ,
969
968
value : {
@@ -973,6 +972,13 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
973
972
} ,
974
973
} ,
975
974
} ;
975
+ const optimisticChatReportActionsData = {
976
+ onyxMethod : Onyx . METHOD . SET ,
977
+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ chatReport . reportID } ` ,
978
+ value : {
979
+ [ reportPreviewAction . reportActionID ] : reportPreviewAction ,
980
+ } ,
981
+ } ;
976
982
977
983
const successData = [
978
984
{
@@ -989,6 +995,15 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
989
995
key : `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ optimisticTransaction . transactionID } ` ,
990
996
value : { pendingAction : null } ,
991
997
} ,
998
+ {
999
+ onyxMethod : Onyx . METHOD . MERGE ,
1000
+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ chatReport . reportID } ` ,
1001
+ value : {
1002
+ [ reportPreviewAction . reportActionID ] : {
1003
+ pendingAction : null ,
1004
+ } ,
1005
+ } ,
1006
+ } ,
992
1007
] ;
993
1008
994
1009
const failureData = [
@@ -1008,7 +1023,6 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
1008
1023
// Change the method to set for new reports because it doesn't exist yet, is faster,
1009
1024
// and we need the data to be available when we navigate to the chat page
1010
1025
optimisticChatReportData . onyxMethod = Onyx . METHOD . SET ;
1011
- optimisticReportActionsData . onyxMethod = Onyx . METHOD . SET ;
1012
1026
optimisticIOUReportData . onyxMethod = Onyx . METHOD . SET ;
1013
1027
1014
1028
// Set and clear pending fields on the chat report
@@ -1053,8 +1067,8 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
1053
1067
} ,
1054
1068
} ;
1055
1069
1056
- // Add an optimistic created action to the optimistic reportActions data
1057
- optimisticReportActionsData . value [ optimisticCreatedAction . reportActionID ] = optimisticCreatedAction ;
1070
+ // Add an optimistic created action to the optimistic chat reportActions data
1071
+ optimisticChatReportActionsData . value [ optimisticCreatedAction . reportActionID ] = optimisticCreatedAction ;
1058
1072
} else {
1059
1073
failureData . push ( {
1060
1074
onyxMethod : Onyx . METHOD . MERGE ,
@@ -1067,7 +1081,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
1067
1081
} ) ;
1068
1082
}
1069
1083
1070
- const optimisticData = [ optimisticChatReportData , optimisticIOUReportData , optimisticReportActionsData , optimisticTransactionData ] ;
1084
+ const optimisticData = [ optimisticChatReportData , optimisticIOUReportData , optimisticChatReportActionsData , optimisticIOUReportActionsData , optimisticTransactionData ] ;
1071
1085
if ( ! _ . isEmpty ( optimisticPersonalDetailListData ) ) {
1072
1086
optimisticData . push ( optimisticPersonalDetailListData ) ;
1073
1087
}
@@ -1081,6 +1095,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType
1081
1095
transactionID : optimisticTransaction . transactionID ,
1082
1096
newIOUReportDetails,
1083
1097
createdReportActionID : isNewChat ? optimisticCreatedAction . reportActionID : 0 ,
1098
+ reportPreviewReportActionID : reportPreviewAction . reportActionID ,
1084
1099
} ,
1085
1100
optimisticData,
1086
1101
successData,
@@ -1115,6 +1130,12 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
1115
1130
login : recipient . login ,
1116
1131
} ;
1117
1132
1133
+ const optimisticReportPreviewAction = ReportActionsUtils . getReportPreviewAction ( chatReport . reportID , iouReport . reportID ) ;
1134
+ optimisticReportPreviewAction . created = DateUtils . getDBTime ( ) ;
1135
+ const message = ReportUtils . getReportPreviewMessage ( iouReport , optimisticReportPreviewAction ) ;
1136
+ optimisticReportPreviewAction . message [ 0 ] . html = message ;
1137
+ optimisticReportPreviewAction . message [ 0 ] . text = message ;
1138
+
1118
1139
const optimisticData = [
1119
1140
{
1120
1141
onyxMethod : Onyx . METHOD . MERGE ,
@@ -1139,6 +1160,13 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
1139
1160
} ,
1140
1161
} ,
1141
1162
} ,
1163
+ {
1164
+ onyxMethod : Onyx . METHOD . MERGE ,
1165
+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ chatReport . reportID } ` ,
1166
+ value : {
1167
+ [ optimisticReportPreviewAction . reportActionID ] : optimisticReportPreviewAction ,
1168
+ } ,
1169
+ } ,
1142
1170
{
1143
1171
onyxMethod : Onyx . METHOD . MERGE ,
1144
1172
key : `${ ONYXKEYS . COLLECTION . REPORT } ${ iouReport . reportID } ` ,
@@ -1196,6 +1224,15 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho
1196
1224
} ,
1197
1225
} ,
1198
1226
} ,
1227
+ {
1228
+ onyxMethod : Onyx . METHOD . MERGE ,
1229
+ key : `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ chatReport . reportID } ` ,
1230
+ value : {
1231
+ [ optimisticReportPreviewAction . reportActionID ] : {
1232
+ created : optimisticReportPreviewAction . created ,
1233
+ } ,
1234
+ } ,
1235
+ } ,
1199
1236
{
1200
1237
onyxMethod : Onyx . METHOD . MERGE ,
1201
1238
key : `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ optimisticTransaction . transactionID } ` ,
0 commit comments