Skip to content
20 changes: 11 additions & 9 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import InvertedFlatList from '@components/InvertedFlatList';
import {withPersonalDetails} from '@components/OnyxProvider';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '@components/withCurrentUserPersonalDetails';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import useAppFocusEvent from '@hooks/useAppFocusEvent';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useReportScrollManager from '@hooks/useReportScrollManager';
Expand Down Expand Up @@ -202,29 +203,30 @@ function ReportActionsList({
prevReportID = report.reportID;
}, [report.reportID]);

useEffect(() => {
const readNewestReportAction = () => {
if (!userActiveSince.current || report.reportID !== prevReportID) {
return;
}

if (ReportUtils.isUnread(report)) {
if (Visibility.isVisible() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) {
Report.readNewestAction(report.reportID);
} else {
readActionSkipped.current = true;
}
if (ReportUtils.isUnread(report) && Visibility.isVisible() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) {
Report.readNewestAction(report.reportID);
} else {
readActionSkipped.current = true;
}
};

useEffect(() => {
readNewestReportAction();
if (currentUnreadMarker || lastVisibleActionCreatedRef.current === report.lastVisibleActionCreated) {
return;
}

cacheUnreadMarkers.delete(report.reportID);
lastVisibleActionCreatedRef.current = report.lastVisibleActionCreated;
setCurrentUnreadMarker(null);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [report.lastVisibleActionCreated, report.reportID]);

useAppFocusEvent(readNewestReportAction);

useEffect(() => {
if (!userActiveSince.current || report.reportID !== prevReportID) {
return;
Expand Down