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

fix: use focus listeners for message read status #35004

Closed
wants to merge 11 commits into from
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
Loading