From 921e6ae0c538bc89b63b50c56e6c36c3a0ea35f1 Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 1 Nov 2022 15:12:28 -0700 Subject: [PATCH 1/7] Remove unused fetchAllReports function --- src/CONST.js | 1 - .../Navigation/AppNavigator/AuthScreens.js | 1 - src/libs/actions/Report.js | 46 ------------------- 3 files changed, 48 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index 9d6f7dcf2a4c..d0e6d260094c 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -348,7 +348,6 @@ const CONST = { SEARCH_RENDER: 'search_render', HOMEPAGE_INITIAL_RENDER: 'homepage_initial_render', REPORT_INITIAL_RENDER: 'report_initial_render', - HOMEPAGE_REPORTS_LOADED: 'homepage_reports_loaded', SWITCH_REPORT: 'switch_report', SIDEBAR_LOADED: 'sidebar_loaded', COLD: 'cold', diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 0b9b62c25916..2c6407f70164 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -86,7 +86,6 @@ class AuthScreens extends React.Component { super(props); Timing.start(CONST.TIMING.HOMEPAGE_INITIAL_RENDER); - Timing.start(CONST.TIMING.HOMEPAGE_REPORTS_LOADED); } componentDidMount() { diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 1c87c0d5a053..d053fb9a840d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -13,7 +13,6 @@ import Navigation from '../Navigation/Navigation'; import * as ActiveClientManager from '../ActiveClientManager'; import Visibility from '../Visibility'; import ROUTES from '../../ROUTES'; -import Timing from './Timing'; import * as DeprecatedAPI from '../deprecatedAPI'; import * as API from '../API'; import CONFIG from '../../CONFIG'; @@ -522,50 +521,6 @@ function fetchOrCreateChatReport(participants, shouldNavigate = true) { }); } -/** - * Get all of our reports - * - * @param {Boolean} shouldRecordHomePageTiming whether or not performance timing should be measured - * @returns {Promise} - */ -function fetchAllReports( - shouldRecordHomePageTiming = false, -) { - Onyx.set(ONYXKEYS.IS_LOADING_REPORT_DATA, true); - return DeprecatedAPI.Get({ - returnValueList: 'chatList', - }) - .then((response) => { - if (response.jsonCode !== 200) { - return; - } - - // The cast here is necessary as Get rvl='chatList' may return an int or Array - const reportIDs = _.filter(String(response.chatList).split(','), _.identity); - - // Get all the chat reports if they have any, otherwise create one with concierge - if (reportIDs.length > 0) { - return fetchChatReportsByIDs(reportIDs); - } - - return fetchOrCreateChatReport([currentUserEmail, CONST.EMAIL.CONCIERGE], false); - }) - .then((returnedReports) => { - Onyx.set(ONYXKEYS.IS_LOADING_REPORT_DATA, false); - - // If at this point the user still doesn't have a Concierge report, create it for them. - // This means they were a participant in reports before their account was created (e.g. default rooms) - const hasConciergeChat = _.some(returnedReports, report => ReportUtils.isConciergeChatReport(report)); - if (!hasConciergeChat) { - fetchOrCreateChatReport([currentUserEmail, CONST.EMAIL.CONCIERGE], false); - } - - if (shouldRecordHomePageTiming) { - Timing.end(CONST.TIMING.HOMEPAGE_REPORTS_LOADED); - } - }); -} - /** * Add up to two report actions to a report. This method can be called for the following situations: * @@ -1503,7 +1458,6 @@ Onyx.connect({ }); export { - fetchAllReports, fetchOrCreateChatReport, fetchChatReportsByIDs, fetchIOUReportByID, From e5a6191a8faa52fe938fa2ee3a6d63aef7408559 Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 1 Nov 2022 15:14:19 -0700 Subject: [PATCH 2/7] Make fetchChatReportsByIDs no longer return a promise --- src/libs/actions/Report.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index d053fb9a840d..c28a34e3a4f4 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -247,12 +247,11 @@ function fetchIOUReportID(debtorEmail) { * when we find an inaccessible chat * @param {Array} chatList * @param {Boolean} shouldRedirectIfInaccessible - * @returns {Promise} only used internally when fetchAllReports() is called */ function fetchChatReportsByIDs(chatList, shouldRedirectIfInaccessible = false) { let fetchedReports; const simplifiedReports = {}; - return DeprecatedAPI.GetReportSummaryList({reportIDList: chatList.join(',')}) + DeprecatedAPI.GetReportSummaryList({reportIDList: chatList.join(',')}) .then(({reportSummaryList, jsonCode}) => { Log.info('[Report] successfully fetched report data', false, {chatList}); fetchedReports = reportSummaryList; From e42fde769b8b4eaffab4cd1c60c366a06b2414cb Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 1 Nov 2022 15:26:14 -0700 Subject: [PATCH 3/7] Remove fetchChatReportsByIDs and replace usages with openReport --- README.md | 2 +- src/libs/actions/Report.js | 92 ++-------------------------------- src/pages/home/ReportScreen.js | 2 +- 3 files changed, 5 insertions(+), 91 deletions(-) diff --git a/README.md b/README.md index d63b6b064532..d456c5e52af4 100644 --- a/README.md +++ b/README.md @@ -311,7 +311,7 @@ This application is built with the following principles. - The UI should never call any Onyx methods except for `Onyx.connect()`. That is the job of Actions (see next section). - The UI always triggers an Action when something needs to happen (eg. a person inputs data, the UI triggers an Action with this data). - The UI should be as flexible as possible when it comes to: - - Incomplete or missing data. Always assume data is incomplete or not there. For example, when a comment is pushed to the client from a pusher event, it's possible that Onyx does not have data for that report yet. That's OK. A partial report object is added to Onyx for the report key `report_1234 = {reportID: 1234, isUnread: true}`. Then there is code that monitors Onyx for reports with incomplete data, and calls `fetchChatReportsByIDs(1234)` to get the full data for that report. The UI should be able to gracefully handle the report object not being complete. In this example, the sidebar wouldn't display any report that does not have a report name. + - Incomplete or missing data. Always assume data is incomplete or not there. For example, when a comment is pushed to the client from a pusher event, it's possible that Onyx does not have data for that report yet. That's OK. A partial report object is added to Onyx for the report key `report_1234 = {reportID: 1234, isUnread: true}`. Then there is code that monitors Onyx for reports with incomplete data, and calls `openReport(1234)` to get the full data for that report. The UI should be able to gracefully handle the report object not being complete. In this example, the sidebar wouldn't display any report that does not have a report name. - The order that actions are done in. All actions should be done in parallel instead of sequence. - Parallel actions are asynchronous methods that don't return promises. Any number of these actions can be called at one time and it doesn't matter what order they happen in or when they complete. - In-Sequence actions are asynchronous methods that return promises. This is necessary when one asynchronous method depends on the results from a previous asynchronous method. Example: Making an XHR to `command=CreateChatReport` which returns a reportID which is used to call `command=Get&rvl=reportStuff`. diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c28a34e3a4f4..5fb6432f8bbd 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -241,91 +241,6 @@ function fetchIOUReportID(debtorEmail) { }); } -/** - * Fetches chat reports when provided a list of chat report IDs. - * If the shouldRedirectIfInaccessible flag is set, we redirect to the Concierge chat - * when we find an inaccessible chat - * @param {Array} chatList - * @param {Boolean} shouldRedirectIfInaccessible - */ -function fetchChatReportsByIDs(chatList, shouldRedirectIfInaccessible = false) { - let fetchedReports; - const simplifiedReports = {}; - DeprecatedAPI.GetReportSummaryList({reportIDList: chatList.join(',')}) - .then(({reportSummaryList, jsonCode}) => { - Log.info('[Report] successfully fetched report data', false, {chatList}); - fetchedReports = reportSummaryList; - - // If we receive a 404 response while fetching a single report, treat that report as inaccessible. - if (jsonCode === 404 && shouldRedirectIfInaccessible) { - throw new Error(CONST.REPORT.ERROR.INACCESSIBLE_REPORT); - } - - return Promise.all(_.map(fetchedReports, (chatReport) => { - // If there aren't any IOU actions, we don't need to fetch any additional data - if (!chatReport.hasIOUAction) { - return; - } - - // Group chat reports cannot and should not be associated with a specific IOU report - const participants = getParticipantEmailsFromReport(chatReport); - if (participants.length > 1) { - return; - } - if (participants.length === 0) { - Log.alert('[Report] Report with IOU action but does not have any participant.', { - reportID: chatReport.reportID, - participants, - }); - return; - } - - return fetchIOUReportID(participants[0]) - .then((iouReportID) => { - if (!iouReportID) { - return Promise.resolve(); - } - - return fetchIOUReport(iouReportID, chatReport.reportID); - }); - })); - }) - .then((iouReportObjects) => { - // Process the reports and store them in Onyx. At the same time we'll save the simplified reports in this - // variable called simplifiedReports which hold the participants (minus the current user) for each report. - // Using this simplifiedReport we can call PersonalDetails.getFromReportParticipants to get the - // personal details of all the participants and even link up their avatars to report icons. - const reportIOUData = {}; - _.each(fetchedReports, (report) => { - const simplifiedReport = getSimplifiedReportObject(report); - simplifiedReports[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`] = simplifiedReport; - }); - - _.each(iouReportObjects, (iouReportObject) => { - if (!iouReportObject) { - return; - } - - const iouReportKey = `${ONYXKEYS.COLLECTION.REPORT_IOUS}${iouReportObject.reportID}`; - const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${iouReportObject.chatReportID}`; - reportIOUData[iouReportKey] = iouReportObject; - simplifiedReports[reportKey].iouReportID = iouReportObject.reportID; - simplifiedReports[reportKey].hasOutstandingIOU = iouReportObject.stateNum - === CONST.REPORT.STATE_NUM.PROCESSING && iouReportObject.total !== 0; - }); - - // We use mergeCollection such that it updates the collection in one go. - // Any withOnyx subscribers to this key will also receive the complete updated props just once - // than updating props for each report and re-rendering had merge been used. - Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT_IOUS, reportIOUData); - Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, simplifiedReports); - - // Fetch the personal details if there are any - PersonalDetails.getFromReportParticipants(_.values(simplifiedReports)); - return simplifiedReports; - }); -} - /** * Given IOU object, save the data to Onyx. * @@ -923,7 +838,7 @@ function handleReportChanged(report) { // A report can be missing a name if a comment is received via pusher event // and the report does not yet exist in Onyx (eg. a new DM created with the logged in person) if (report.reportID && report.reportName === undefined) { - fetchChatReportsByIDs([report.reportID]); + openReport(report.reportID); } } @@ -1204,8 +1119,8 @@ function addPolicyReport(policy, reportName, visibility) { ); // Onyx.set is used on the optimistic data so that it is present before navigating to the workspace room. With Onyx.merge the workspace room reportID is not present when - // fetchReportIfNeeded is called on the ReportScreen, so fetchChatReportsByIDs is called which is unnecessary since the optimistic data will be stored in Onyx. - // If there was an error creating the room, then fetchChatReportsByIDs throws an error and the user is navigated away from the report instead of showing the RBR error message. + // fetchReportIfNeeded is called on the ReportScreen, so openReport is called which is unnecessary since the optimistic data will be stored in Onyx. + // If there was an error creating the room, then openReport throws an error and the user is navigated away from the report instead of showing the RBR error message. // Therefore, Onyx.set is used instead of Onyx.merge. const optimisticData = [ { @@ -1458,7 +1373,6 @@ Onyx.connect({ export { fetchOrCreateChatReport, - fetchChatReportsByIDs, fetchIOUReportByID, addComment, addAttachment, diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index d85dabdf9dcd..3b86df811a0a 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -172,7 +172,7 @@ class ReportScreen extends React.Component { return; } - Report.fetchChatReportsByIDs([reportIDFromPath], true); + Report.openReport(reportIDFromPath); } /** From 56dc4e2c52390f7a5639232cbba744bc5880e6b6 Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 1 Nov 2022 15:42:20 -0700 Subject: [PATCH 4/7] Stop returning a promise from fetchOrCreateChatReport --- src/libs/actions/Report.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 5fb6432f8bbd..6a6255587d4b 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -400,14 +400,13 @@ function unsubscribeFromReportChannel(reportID) { * * @param {String[]} participants * @param {Boolean} shouldNavigate - * @returns {Promise} */ function fetchOrCreateChatReport(participants, shouldNavigate = true) { if (participants.length < 2) { throw new Error('fetchOrCreateChatReport() must have at least two participants.'); } - return DeprecatedAPI.CreateChatReport({ + DeprecatedAPI.CreateChatReport({ emailList: participants.join(','), }) .then((data) => { @@ -428,10 +427,6 @@ function fetchOrCreateChatReport(participants, shouldNavigate = true) { // Redirect the logged in person to the new report Navigation.navigate(ROUTES.getReportRoute(data.reportID)); } - - // We are returning an array with a report object here since fetchAllReports calls this method or - // fetchChatReportsByIDs which returns an array of report objects. - return [simplifiedReportObject]; }); } From 0af12918be616ce05428aeab64378465355b093c Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 1 Nov 2022 15:47:07 -0700 Subject: [PATCH 5/7] Remove unused INACCESSIBLE_REPORT error --- src/CONST.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index d0e6d260094c..5cd06c0eef28 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -262,9 +262,6 @@ const CONST = { REMOVED_FROM_POLICY: 'removedFromPolicy', POLICY_DELETED: 'policyDeleted', }, - ERROR: { - INACCESSIBLE_REPORT: 'Report not found', - }, MESSAGE: { TYPE: { COMMENT: 'COMMENT', From c8e3c9175e2ed93bdf8325e88b09bb4c93b226aa Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 1 Nov 2022 15:48:15 -0700 Subject: [PATCH 6/7] Remove unused GetReportSummaryList --- src/libs/deprecatedAPI.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/libs/deprecatedAPI.js b/src/libs/deprecatedAPI.js index 7db326b66713..0134d00b06fa 100644 --- a/src/libs/deprecatedAPI.js +++ b/src/libs/deprecatedAPI.js @@ -481,17 +481,6 @@ function Inbox_CallUser(parameters) { return Network.post(commandName, parameters); } -/** - * @param {Object} parameters - * @param {String} parameters.reportIDList - * @returns {Promise} - */ -function GetReportSummaryList(parameters) { - const commandName = 'Get'; - requireParameters(['reportIDList'], parameters, commandName); - return Network.post(commandName, {...parameters, returnValueList: 'reportSummaryList'}); -} - /** * Transfer Wallet balance and takes either the bankAccoundID or fundID * @param {Object} parameters @@ -529,7 +518,6 @@ export { GetIOUReport, GetFullPolicy, GetPolicySummaryList, - GetReportSummaryList, Graphite_Timer, Inbox_CallUser, PayIOU, From 739c4ea9455d77434a5df5354eaa68534a97410f Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 1 Nov 2022 16:00:02 -0700 Subject: [PATCH 7/7] Remove unused fetchIOUReportID function --- src/libs/actions/Report.js | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 6a6255587d4b..e9fcec9f2213 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -215,32 +215,6 @@ function fetchIOUReport(iouReportID, chatReportID) { }); } -/** - * Given debtorEmail finds active IOU report ID via GetIOUReport API call - * - * @param {String} debtorEmail - * @returns {Promise} - */ -function fetchIOUReportID(debtorEmail) { - return DeprecatedAPI.GetIOUReport({ - debtorEmail, - }).then((response) => { - const iouReportID = response.reportID || 0; - if (response.jsonCode !== 200) { - console.error(response.message); - return; - } - if (iouReportID === 0) { - // If there is no IOU report for this user then we will assume it has been paid and do nothing here. - // All reports are initialized with hasOutstandingIOU: false. Since the IOU report we were looking for has - // been settled then there's nothing more to do. - Log.info('GetIOUReport returned a reportID of 0, not fetching IOU report data'); - return; - } - return iouReportID; - }); -} - /** * Given IOU object, save the data to Onyx. *