Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if reports data is up to date before update last read action id #6095

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,7 @@ export default {

// Are report actions loading?
IS_LOADING_REPORT_ACTIONS: 'isLoadingReportActions',

// Is report data loading?
IS_LOADING_REPORT_DATA: 'isLoadingReportData',
};
14 changes: 14 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -936,6 +943,7 @@ function fetchAllReports(
shouldRecordHomePageTiming = false,
shouldDelayActionsFetch = false,
) {
Onyx.set(ONYXKEYS.IS_LOADING_REPORT_DATA, true);
return API.Get({
returnValueList: 'chatList',
})
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down