From 9a5b7c4352ef2fb05985e7919ce1f897ce2eb21c Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Mon, 15 Mar 2021 14:03:06 -0700 Subject: [PATCH 1/9] add GetIOUReport api command --- src/libs/API.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/API.js b/src/libs/API.js index 852dee8497d8..d3b7d9378519 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -605,7 +605,6 @@ function SetNameValuePair(parameters) { } /** - * * @param {Object} parameters * @param {String[]} data * @returns {Promise} @@ -621,6 +620,17 @@ function Mobile_GetConstants(parameters) { return Network.post(commandName, finalParameters); } +/** + * @param {Object} parameters + * @param {String} parameters.debtorEmail + * @returns {Promise} + */ +function GetIOUReport(parameters) { + const commandName = 'GetIOUReport'; + requireParameters(['debtorEmail'], parameters, commandName); + return Network.post(commandName, parameters); +} + export { getAuthToken, Authenticate, @@ -630,6 +640,7 @@ export { DeleteLogin, Get, GetAccountStatus, + GetIOUReport, GetRequestCountryCode, Graphite_Timer, Log, From ab38d478ac912b06529bd0e1b1eb5381cbdce8e2 Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Mon, 15 Mar 2021 18:51:24 -0700 Subject: [PATCH 2/9] start persisting IOUReport data in onyx --- src/ONYXKEYS.js | 1 + src/libs/actions/Report.js | 81 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index b9057c941645..feb0ae043567 100644 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -61,5 +61,6 @@ export default { REPORT_ACTIONS: 'reportActions_', REPORT_DRAFT_COMMENT: 'reportDraftComment_', REPORT_USER_IS_TYPING: 'reportUserIsTyping_', + REPORT_IOUS: 'reportIOUs_', }, }; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 3a746aef0156..b88262803e42 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -495,6 +495,85 @@ function fetchChatReports() { }); } +/** + * Get a simplified version of an IOU report + * + * @param {Number} reportID + * @param {Object} reportData + * @param {Number} reportData.transactionID + * @param {Number} reportData.amount + * @param {String} reportData.currency + * @param {String} reportData.created + * @param {String} reportData.comment + * @param {Object[]} reportData.transactionList + * @param {String} reportData.ownerEmail + * @param {String} reportData.managerEmail + * @returns {Object} + */ +function getSimplifiedIOUReport(reportID, reportData) { + const transactions = _.map(reportData.transactionList, transaction => ({ + transactionID: transaction.transactionID, + amount: transaction.amount, + currency: transaction.currency, + created: transaction.created, + comment: transaction.comment, + })); + + return { + reportID, + ownerEmail: reportData.ownerEmail, + managerEmail: reportData.managerEmail, + currency: reportData.currency, + transactions, + }; +} + +/** + * Fetches the updated data for an IOU Report and updates the IOU collection in ONYX + * + * @param {Number} reportID + * @param {Object[]} reportHistory + */ +function updateIOUReportData(reportID, reportHistory) { + const containsIOUAction = _.any(reportHistory, action => action.actionName === 'IOU'); + + // If there aren't any IOU actions, we don't need to fetch any additional data + if (!containsIOUAction) { + return; + } + + const otherParticipants = _.chain(reportHistory) + .pluck('actorEmail') + .unique() + .without(currentUserEmail) + .value(); + + // If we have more than one participant, this is not an IOU + if (otherParticipants.length > 1) { + return; + } + + // If we have an IOU action, get the IOU reportID + let iouReportID = 0; + API.GetIOUReport({ + debtorEmail: otherParticipants[0], + }).then((response) => { + iouReportID = response.reportID; + + Log.info('[Report] Fetching IOU report data', true, iouReportID); + return API.Get({ + returnValueList: 'reportStuff', + reportIDList: iouReportID, + shouldLoadOptionalKeys: true, + includePinnedReports: true, + }); + }).then((response) => { + const iouReportData = response.reports[iouReportID]; + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReportID}`, + getSimplifiedIOUReport(iouReportID, iouReportData)); + }); +} + /** * Get the actions of a report * @@ -529,6 +608,8 @@ function fetchActions(reportID, offset) { .max() .value(); + updateIOUReportData(reportID, indexedData); + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, indexedData); Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {maxSequenceNumber}); }); From a673476ef0309695316a29d31ea614ed7b2cb353 Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Tue, 16 Mar 2021 13:59:00 -0700 Subject: [PATCH 3/9] remove unused param, add comments --- src/libs/actions/Report.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index b88262803e42..4bc910c4c3ac 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -529,12 +529,11 @@ function getSimplifiedIOUReport(reportID, reportData) { } /** - * Fetches the updated data for an IOU Report and updates the IOU collection in ONYX + * Fetches the updated data for an IOU Report and updates the IOU collection in Onyx * - * @param {Number} reportID * @param {Object[]} reportHistory */ -function updateIOUReportData(reportID, reportHistory) { +function updateIOUReportData(reportHistory) { const containsIOUAction = _.any(reportHistory, action => action.actionName === 'IOU'); // If there aren't any IOU actions, we don't need to fetch any additional data @@ -553,14 +552,14 @@ function updateIOUReportData(reportID, reportHistory) { return; } - // If we have an IOU action, get the IOU reportID + // Since the Chat and the IOU are different reports with different reportIDs, and GetIOUReport only returns the + // IOU's reportID, keep track of the IOU's reportID so we can use it to get the IOUReport data via `GetReportStuff` let iouReportID = 0; API.GetIOUReport({ debtorEmail: otherParticipants[0], }).then((response) => { iouReportID = response.reportID; - Log.info('[Report] Fetching IOU report data', true, iouReportID); return API.Get({ returnValueList: 'reportStuff', reportIDList: iouReportID, @@ -608,7 +607,7 @@ function fetchActions(reportID, offset) { .max() .value(); - updateIOUReportData(reportID, indexedData); + updateIOUReportData(indexedData); Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, indexedData); Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {maxSequenceNumber}); From d27bed5759c35c6ddf89cfc8c6cbe80d17ea02c8 Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Wed, 17 Mar 2021 17:08:49 -0700 Subject: [PATCH 4/9] remove unnecessary param --- src/libs/actions/Report.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 4bc910c4c3ac..82e0a7a3404b 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -498,7 +498,6 @@ function fetchChatReports() { /** * Get a simplified version of an IOU report * - * @param {Number} reportID * @param {Object} reportData * @param {Number} reportData.transactionID * @param {Number} reportData.amount @@ -508,9 +507,10 @@ function fetchChatReports() { * @param {Object[]} reportData.transactionList * @param {String} reportData.ownerEmail * @param {String} reportData.managerEmail + * @param {Number} reportData.reportID * @returns {Object} */ -function getSimplifiedIOUReport(reportID, reportData) { +function getSimplifiedIOUReport(reportData) { const transactions = _.map(reportData.transactionList, transaction => ({ transactionID: transaction.transactionID, amount: transaction.amount, @@ -520,7 +520,7 @@ function getSimplifiedIOUReport(reportID, reportData) { })); return { - reportID, + reportID: reportData.reportID, ownerEmail: reportData.ownerEmail, managerEmail: reportData.managerEmail, currency: reportData.currency, @@ -569,7 +569,7 @@ function updateIOUReportData(reportHistory) { }).then((response) => { const iouReportData = response.reports[iouReportID]; Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReportID}`, - getSimplifiedIOUReport(iouReportID, iouReportData)); + getSimplifiedIOUReport(iouReportData)); }); } From 698328d218c37c2e1d7b04abe43727677e92ff07 Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Thu, 18 Mar 2021 17:10:18 -0700 Subject: [PATCH 5/9] update getIOUReport to use reportID --- src/libs/API.js | 4 ++-- src/libs/actions/Report.js | 18 ++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/libs/API.js b/src/libs/API.js index d3b7d9378519..aba42b923c99 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -622,12 +622,12 @@ function Mobile_GetConstants(parameters) { /** * @param {Object} parameters - * @param {String} parameters.debtorEmail + * @param {Number} parameters.reportID * @returns {Promise} */ function GetIOUReport(parameters) { const commandName = 'GetIOUReport'; - requireParameters(['debtorEmail'], parameters, commandName); + requireParameters(['reportID'], parameters, commandName); return Network.post(commandName, parameters); } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 82e0a7a3404b..45e0da5b8d56 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -531,9 +531,10 @@ function getSimplifiedIOUReport(reportData) { /** * Fetches the updated data for an IOU Report and updates the IOU collection in Onyx * + * @param {Number} reportID * @param {Object[]} reportHistory */ -function updateIOUReportData(reportHistory) { +function updateIOUReportData(reportID, reportHistory) { const containsIOUAction = _.any(reportHistory, action => action.actionName === 'IOU'); // If there aren't any IOU actions, we don't need to fetch any additional data @@ -541,22 +542,11 @@ function updateIOUReportData(reportHistory) { return; } - const otherParticipants = _.chain(reportHistory) - .pluck('actorEmail') - .unique() - .without(currentUserEmail) - .value(); - - // If we have more than one participant, this is not an IOU - if (otherParticipants.length > 1) { - return; - } - // Since the Chat and the IOU are different reports with different reportIDs, and GetIOUReport only returns the // IOU's reportID, keep track of the IOU's reportID so we can use it to get the IOUReport data via `GetReportStuff` let iouReportID = 0; API.GetIOUReport({ - debtorEmail: otherParticipants[0], + reportID, }).then((response) => { iouReportID = response.reportID; @@ -607,7 +597,7 @@ function fetchActions(reportID, offset) { .max() .value(); - updateIOUReportData(indexedData); + updateIOUReportData(reportID, indexedData); Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, indexedData); Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {maxSequenceNumber}); From 7b89e7d017bcc7483f7352e640093e6d427cd77e Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Fri, 19 Mar 2021 11:35:39 -0700 Subject: [PATCH 6/9] update onyx collection inside fetchChatReportsByIDs --- src/libs/API.js | 4 ++-- src/libs/actions/Report.js | 41 +++++++++++++++++++++++++++++--------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/libs/API.js b/src/libs/API.js index aba42b923c99..d3b7d9378519 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -622,12 +622,12 @@ function Mobile_GetConstants(parameters) { /** * @param {Object} parameters - * @param {Number} parameters.reportID + * @param {String} parameters.debtorEmail * @returns {Promise} */ function GetIOUReport(parameters) { const commandName = 'GetIOUReport'; - requireParameters(['reportID'], parameters, commandName); + requireParameters(['debtorEmail'], parameters, commandName); return Network.post(commandName, parameters); } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 45e0da5b8d56..89244cfeb3bb 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -184,7 +184,9 @@ function fetchChatReportsByIDs(chatList) { const simplifiedReports = {}; _.each(fetchedReports, (report) => { const key = `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`; - simplifiedReports[key] = getSimplifiedReportObject(report); + const simplifiedReport = getSimplifiedReportObject(report); + simplifiedReports[key] = simplifiedReport; + updateIOUReportData(report, simplifiedReport.participants); }); // We use mergeCollection such that it updates ONYXKEYS.COLLECTION.REPORT in one go. @@ -531,24 +533,35 @@ function getSimplifiedIOUReport(reportData) { /** * Fetches the updated data for an IOU Report and updates the IOU collection in Onyx * - * @param {Number} reportID - * @param {Object[]} reportHistory + * @param {Object} report + * @param {String[]} participants */ -function updateIOUReportData(reportID, reportHistory) { - const containsIOUAction = _.any(reportHistory, action => action.actionName === 'IOU'); +function updateIOUReportData(report, participants) { + const reportActionList = lodashGet(report, ['reportActionList'], []); + const containsIOUAction = _.any(reportActionList, reportAction => reportAction.action === 'IOU'); // If there aren't any IOU actions, we don't need to fetch any additional data if (!containsIOUAction) { return; } + // If we don't have one participant, this is not an IOU + if (participants.length !== 1) { + return; + } + // Since the Chat and the IOU are different reports with different reportIDs, and GetIOUReport only returns the // IOU's reportID, keep track of the IOU's reportID so we can use it to get the IOUReport data via `GetReportStuff` let iouReportID = 0; API.GetIOUReport({ - reportID, + debtorEmail: participants[0], }).then((response) => { - iouReportID = response.reportID; + iouReportID = response.reportID || 0; + if (response.jsonCode !== 200) { + throw new Error(response.message); + } else if (iouReportID === 0) { + throw new Error('GetIOUReport returned a reportID of 0'); + } return API.Get({ returnValueList: 'reportStuff', @@ -557,9 +570,21 @@ function updateIOUReportData(reportID, reportHistory) { includePinnedReports: true, }); }).then((response) => { + if (response.jsonCode !== 200) { + throw new Error(response.message); + } else if (response.reports.length === 0) { + throw new Error('Empty reportList returned from Get_ReportStuff'); + } + const iouReportData = response.reports[iouReportID]; + if (!iouReportData) { + throw new Error(`No iouReportData found for reportID ${iouReportID}`); + } + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReportID}`, getSimplifiedIOUReport(iouReportData)); + }).catch((error) => { + console.debug(`[Report] Failed to populate IOU Collection: ${error.message}`); }); } @@ -597,8 +622,6 @@ function fetchActions(reportID, offset) { .max() .value(); - updateIOUReportData(reportID, indexedData); - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, indexedData); Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {maxSequenceNumber}); }); From 389f8cfd20b5625aa0eaf6a54b89a9282b2f7534 Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Fri, 19 Mar 2021 11:36:35 -0700 Subject: [PATCH 7/9] move def above usage --- src/libs/actions/Report.js | 182 ++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 89244cfeb3bb..9bc48b746e8c 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -158,6 +158,97 @@ function getSimplifiedReportObject(report) { }; } +/** + * Get a simplified version of an IOU report + * + * @param {Object} reportData + * @param {Number} reportData.transactionID + * @param {Number} reportData.amount + * @param {String} reportData.currency + * @param {String} reportData.created + * @param {String} reportData.comment + * @param {Object[]} reportData.transactionList + * @param {String} reportData.ownerEmail + * @param {String} reportData.managerEmail + * @param {Number} reportData.reportID + * @returns {Object} + */ +function getSimplifiedIOUReport(reportData) { + const transactions = _.map(reportData.transactionList, transaction => ({ + transactionID: transaction.transactionID, + amount: transaction.amount, + currency: transaction.currency, + created: transaction.created, + comment: transaction.comment, + })); + + return { + reportID: reportData.reportID, + ownerEmail: reportData.ownerEmail, + managerEmail: reportData.managerEmail, + currency: reportData.currency, + transactions, + }; +} + +/** + * Fetches the updated data for an IOU Report and updates the IOU collection in Onyx + * + * @param {Object} report + * @param {String[]} participants + */ +function updateIOUReportData(report, participants) { + const reportActionList = lodashGet(report, ['reportActionList'], []); + const containsIOUAction = _.any(reportActionList, reportAction => reportAction.action === 'IOU'); + + // If there aren't any IOU actions, we don't need to fetch any additional data + if (!containsIOUAction) { + return; + } + + // If we don't have one participant, this is not an IOU + if (participants.length !== 1) { + return; + } + + // Since the Chat and the IOU are different reports with different reportIDs, and GetIOUReport only returns the + // IOU's reportID, keep track of the IOU's reportID so we can use it to get the IOUReport data via `GetReportStuff` + let iouReportID = 0; + API.GetIOUReport({ + debtorEmail: participants[0], + }).then((response) => { + iouReportID = response.reportID || 0; + if (response.jsonCode !== 200) { + throw new Error(response.message); + } else if (iouReportID === 0) { + throw new Error('GetIOUReport returned a reportID of 0'); + } + + return API.Get({ + returnValueList: 'reportStuff', + reportIDList: iouReportID, + shouldLoadOptionalKeys: true, + includePinnedReports: true, + }); + }).then((response) => { + if (response.jsonCode !== 200) { + throw new Error(response.message); + } else if (response.reports.length === 0) { + throw new Error('Empty reportList returned from Get_ReportStuff'); + } + + const iouReportData = response.reports[iouReportID]; + if (!iouReportData) { + throw new Error(`No iouReportData found for reportID ${iouReportID}`); + } + + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReportID}`, + getSimplifiedIOUReport(iouReportData)); + }).catch((error) => { + console.debug(`[Report] Failed to populate IOU Collection: ${error.message}`); + }); +} + /** * Fetches chat reports when provided a list of * chat report IDs @@ -497,97 +588,6 @@ function fetchChatReports() { }); } -/** - * Get a simplified version of an IOU report - * - * @param {Object} reportData - * @param {Number} reportData.transactionID - * @param {Number} reportData.amount - * @param {String} reportData.currency - * @param {String} reportData.created - * @param {String} reportData.comment - * @param {Object[]} reportData.transactionList - * @param {String} reportData.ownerEmail - * @param {String} reportData.managerEmail - * @param {Number} reportData.reportID - * @returns {Object} - */ -function getSimplifiedIOUReport(reportData) { - const transactions = _.map(reportData.transactionList, transaction => ({ - transactionID: transaction.transactionID, - amount: transaction.amount, - currency: transaction.currency, - created: transaction.created, - comment: transaction.comment, - })); - - return { - reportID: reportData.reportID, - ownerEmail: reportData.ownerEmail, - managerEmail: reportData.managerEmail, - currency: reportData.currency, - transactions, - }; -} - -/** - * Fetches the updated data for an IOU Report and updates the IOU collection in Onyx - * - * @param {Object} report - * @param {String[]} participants - */ -function updateIOUReportData(report, participants) { - const reportActionList = lodashGet(report, ['reportActionList'], []); - const containsIOUAction = _.any(reportActionList, reportAction => reportAction.action === 'IOU'); - - // If there aren't any IOU actions, we don't need to fetch any additional data - if (!containsIOUAction) { - return; - } - - // If we don't have one participant, this is not an IOU - if (participants.length !== 1) { - return; - } - - // Since the Chat and the IOU are different reports with different reportIDs, and GetIOUReport only returns the - // IOU's reportID, keep track of the IOU's reportID so we can use it to get the IOUReport data via `GetReportStuff` - let iouReportID = 0; - API.GetIOUReport({ - debtorEmail: participants[0], - }).then((response) => { - iouReportID = response.reportID || 0; - if (response.jsonCode !== 200) { - throw new Error(response.message); - } else if (iouReportID === 0) { - throw new Error('GetIOUReport returned a reportID of 0'); - } - - return API.Get({ - returnValueList: 'reportStuff', - reportIDList: iouReportID, - shouldLoadOptionalKeys: true, - includePinnedReports: true, - }); - }).then((response) => { - if (response.jsonCode !== 200) { - throw new Error(response.message); - } else if (response.reports.length === 0) { - throw new Error('Empty reportList returned from Get_ReportStuff'); - } - - const iouReportData = response.reports[iouReportID]; - if (!iouReportData) { - throw new Error(`No iouReportData found for reportID ${iouReportID}`); - } - - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReportID}`, - getSimplifiedIOUReport(iouReportData)); - }).catch((error) => { - console.debug(`[Report] Failed to populate IOU Collection: ${error.message}`); - }); -} - /** * Get the actions of a report * From 07e06b3272b5016850ca20c2373dc6f2e91b7716 Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Fri, 19 Mar 2021 13:04:30 -0700 Subject: [PATCH 8/9] get participants from report, clean up error handling --- src/CONST.js | 3 +++ src/libs/actions/Report.js | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 6e4841f27de4..675a80f47217 100644 --- a/src/CONST.js +++ b/src/CONST.js @@ -21,6 +21,9 @@ const CONST = { REPORT: { MAXIMUM_PARTICIPANTS: 8, REPORT_ACTIONS_LIMIT: 50, + REPORT_ACTION_TYPE: { + IOU: 'IOU', + }, }, MODAL: { MODAL_TYPE: { diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 9bc48b746e8c..123f0ad334cd 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -195,19 +195,25 @@ function getSimplifiedIOUReport(reportData) { * Fetches the updated data for an IOU Report and updates the IOU collection in Onyx * * @param {Object} report - * @param {String[]} participants + * @param {Object[]} report.reportActionList + * @param {Number} report.reportID */ -function updateIOUReportData(report, participants) { - const reportActionList = lodashGet(report, ['reportActionList'], []); - const containsIOUAction = _.any(reportActionList, reportAction => reportAction.action === 'IOU'); +function updateIOUReportData(report) { + const reportActionList = report.reportActionList || []; + const containsIOUAction = _.any(reportActionList, + reportAction => reportAction.action === CONST.REPORT.REPORT_ACTION_TYPE.IOU); // If there aren't any IOU actions, we don't need to fetch any additional data if (!containsIOUAction) { return; } - // If we don't have one participant, this is not an IOU + // If we don't have one participant (other than the current user), this is not an IOU + const participants = getParticipantEmailsFromReport(report); if (participants.length !== 1) { + Log.alert('[Report] Report with IOU action has more than 2 participants', true, { + reportID: report.reportID, + }); return; } @@ -221,7 +227,7 @@ function updateIOUReportData(report, participants) { if (response.jsonCode !== 200) { throw new Error(response.message); } else if (iouReportID === 0) { - throw new Error('GetIOUReport returned a reportID of 0'); + throw new Error('GetIOUReport returned a reportID of 0, not fetching IOU report data'); } return API.Get({ @@ -233,8 +239,6 @@ function updateIOUReportData(report, participants) { }).then((response) => { if (response.jsonCode !== 200) { throw new Error(response.message); - } else if (response.reports.length === 0) { - throw new Error('Empty reportList returned from Get_ReportStuff'); } const iouReportData = response.reports[iouReportID]; @@ -277,7 +281,7 @@ function fetchChatReportsByIDs(chatList) { const key = `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`; const simplifiedReport = getSimplifiedReportObject(report); simplifiedReports[key] = simplifiedReport; - updateIOUReportData(report, simplifiedReport.participants); + updateIOUReportData(report); }); // We use mergeCollection such that it updates ONYXKEYS.COLLECTION.REPORT in one go. From d8b9eb500332bf555a4b31f64c5ee26f054c789e Mon Sep 17 00:00:00 2001 From: Joe Gambino Date: Fri, 19 Mar 2021 13:23:42 -0700 Subject: [PATCH 9/9] update const, add participants to log --- src/CONST.js | 8 +++++--- src/libs/actions/Report.js | 5 +++-- src/pages/home/report/ReportActionsView.js | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 675a80f47217..8739dc4b6f18 100644 --- a/src/CONST.js +++ b/src/CONST.js @@ -20,9 +20,11 @@ const CONST = { }, REPORT: { MAXIMUM_PARTICIPANTS: 8, - REPORT_ACTIONS_LIMIT: 50, - REPORT_ACTION_TYPE: { - IOU: 'IOU', + ACTIONS: { + LIMIT: 50, + TYPE: { + IOU: 'IOU', + }, }, }, MODAL: { diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 123f0ad334cd..c134435a279f 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -201,7 +201,7 @@ function getSimplifiedIOUReport(reportData) { function updateIOUReportData(report) { const reportActionList = report.reportActionList || []; const containsIOUAction = _.any(reportActionList, - reportAction => reportAction.action === CONST.REPORT.REPORT_ACTION_TYPE.IOU); + reportAction => reportAction.action === CONST.REPORT.ACTIONS.TYPE.IOU); // If there aren't any IOU actions, we don't need to fetch any additional data if (!containsIOUAction) { @@ -213,6 +213,7 @@ function updateIOUReportData(report) { if (participants.length !== 1) { Log.alert('[Report] Report with IOU action has more than 2 participants', true, { reportID: report.reportID, + participants, }); return; } @@ -613,7 +614,7 @@ function fetchActions(reportID, offset) { return API.Report_GetHistory({ reportID, reportActionsOffset, - reportActionsLimit: CONST.REPORT.REPORT_ACTIONS_LIMIT, + reportActionsLimit: CONST.REPORT.ACTIONS.LIMIT, }) .then((data) => { // We must remove all optimistic actions so there will not be any stuck comments. At this point, we should diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 4d626ebba79b..9fc3d0a42542 100644 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -209,9 +209,9 @@ class ReportActionsView extends React.Component { } this.setState({isLoadingMoreChats: true}, () => { - // Retrieve the next REPORT_ACTIONS_LIMIT sized page of comments, unless we're near the beginning, in which + // Retrieve the next REPORT.ACTIONS.LIMIT sized page of comments, unless we're near the beginning, in which // case just get everything starting from 0. - const offset = Math.max(minSequenceNumber - CONST.REPORT.REPORT_ACTIONS_LIMIT, 0); + const offset = Math.max(minSequenceNumber - CONST.REPORT.ACTIONS.LIMIT, 0); fetchActions(this.props.reportID, offset) .then(() => this.setState({isLoadingMoreChats: false})); });