diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index 947d0aaf0c31..6cc10430cea6 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -147,4 +147,7 @@ export default { // Are report actions loading? IS_LOADING_REPORT_ACTIONS: 'isLoadingReportActions', + + // Is report data loading? + IS_LOADING_REPORT_DATA: 'isLoadingReportData', }; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 438618944270..8e6947466540 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -80,6 +80,13 @@ const lastReadSequenceNumbers = {}; // since we will then be up to date and any optimistic actions that are still waiting to be replaced can be removed. const optimisticReportActionIDs = {}; +// Boolean to indicate if report data is loading from the API or not. +let isReportDataLoading = true; +Onyx.connect({ + key: ONYXKEYS.IS_LOADING_REPORT_DATA, + callback: val => isReportDataLoading = val, +}); + /** * Checks the report to see if there are any unread action items * @@ -936,6 +943,7 @@ function fetchAllReports( shouldRecordHomePageTiming = false, shouldDelayActionsFetch = false, ) { + Onyx.set(ONYXKEYS.IS_LOADING_REPORT_DATA, true); return API.Get({ returnValueList: 'chatList', }) @@ -956,6 +964,7 @@ function fetchAllReports( }) .then((returnedReports) => { Onyx.set(ONYXKEYS.INITIAL_REPORT_DATA_LOADED, true); + 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) @@ -1173,6 +1182,11 @@ function deleteReportComment(reportID, reportAction) { * is last read (meaning that the entire report history has been read) */ function updateLastReadActionID(reportID, sequenceNumber) { + // If report data is loading, we can't update the last read sequence number because it is obsolete + if (isReportDataLoading) { + return; + } + // If we aren't specifying a sequenceNumber and have no valid maxSequenceNumber for this report then we should not // update the last read. Most likely, we have just created the report and it has no comments. But we should err on // the side of caution and do nothing in this case.