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 - Mark the chat as "read" immediately upon switching to the tab #34537

Merged
Prev Previous commit
Next Next commit
refined logic
  • Loading branch information
FitseTLT committed Jan 21, 2024
commit 1a022dafedd9c745eadd87bfa44cd34c580ddd80
21 changes: 19 additions & 2 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function ReportActionsList({
const route = useRoute();
const opacity = useSharedValue(0);
const userActiveSince = useRef(null);
const userInactiveSince = useRef(null);

const markerInit = () => {
if (!cacheUnreadMarkers.has(report.reportID)) {
Expand Down Expand Up @@ -412,7 +413,23 @@ function ReportActionsList({
}, [calculateUnreadMarker, report.lastReadTime, messageManuallyMarkedUnread]);

const onVisibilityChange = useCallback(() => {
if (!Visibility.isVisible() || scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD || userActiveSince.current > (report.lastVisibleActionCreated || '')) {
if (!Visibility.isVisible()) {
userInactiveSince.current = DateUtils.getDBTime();
return;
}

if (
scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD ||
!(
sortedVisibleReportActions &&
_.some(
sortedVisibleReportActions,
(reportAction) =>
userInactiveSince.current < reportAction.created &&
(ReportActionsUtils.isReportPreviewAction(reportAction) ? !reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID(),
)
)
) {
return;
}

Expand All @@ -421,7 +438,7 @@ function ReportActionsList({
setCurrentUnreadMarker(null);
cacheUnreadMarkers.delete(report.reportID);
calculateUnreadMarker();
}, [calculateUnreadMarker, report]);
}, [calculateUnreadMarker, report, sortedVisibleReportActions]);

useEffect(() => {
const unsubscribeVisibilityListener = Visibility.onVisibilityChange(onVisibilityChange);
Expand Down