From c47259067794e726526d55ed079174e5386fcd41 Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Mon, 29 Jan 2024 12:15:52 +0000 Subject: [PATCH] Revert "Merge pull request #34537 from FitseTLT/fix-mark-as-read-on-visibility-change" This reverts commit 77814e546b8dac46081358e11ccdf47ac3a5b431, reversing changes made to b0e2a92a3d856109b6cce916370ec8435770e2af. --- src/libs/actions/Report.ts | 7 +--- src/pages/home/report/ReportActionsList.js | 46 +--------------------- 2 files changed, 3 insertions(+), 50 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 6222c09a898e..12bd7e3170a3 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -929,7 +929,7 @@ function expandURLPreview(reportID: string, reportActionID: string) { } /** Marks the new report actions as read */ -function readNewestAction(reportID: string, shouldEmitEvent = true) { +function readNewestAction(reportID: string) { const lastReadTime = DateUtils.getDBTime(); const optimisticData: OnyxUpdate[] = [ @@ -948,11 +948,6 @@ function readNewestAction(reportID: string, shouldEmitEvent = true) { }; API.write(WRITE_COMMANDS.READ_NEWEST_ACTION, parameters, {optimisticData}); - - if (!shouldEmitEvent) { - return; - } - DeviceEventEmitter.emit(`readNewestAction_${reportID}`, lastReadTime); } diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index ce8dcb10ef5f..8d79e7af8dd4 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -143,7 +143,6 @@ function ReportActionsList({ const route = useRoute(); const opacity = useSharedValue(0); const userActiveSince = useRef(null); - const userInactiveSince = useRef(null); const markerInit = () => { if (!cacheUnreadMarkers.has(report.reportID)) { @@ -388,7 +387,7 @@ function ReportActionsList({ [currentUnreadMarker, sortedVisibleReportActions, report.reportID, messageManuallyMarkedUnread], ); - const calculateUnreadMarker = useCallback(() => { + useEffect(() => { // Iterate through the report actions and set appropriate unread marker. // This is to avoid a warning of: // Cannot update a component (ReportActionsList) while rendering a different component (CellRenderer). @@ -406,48 +405,7 @@ function ReportActionsList({ if (!markerFound) { setCurrentUnreadMarker(null); } - }, [sortedVisibleReportActions, shouldDisplayNewMarker, currentUnreadMarker, report.reportID]); - - useEffect(() => { - calculateUnreadMarker(); - }, [calculateUnreadMarker, report.lastReadTime, messageManuallyMarkedUnread]); - - const onVisibilityChange = useCallback(() => { - if (!Visibility.isVisible()) { - userInactiveSince.current = DateUtils.getDBTime(); - return; - } - // In case the user read new messages (after being inactive) with other device we should - // show marker based on report.lastReadTime - const newMessageTimeReference = userInactiveSince.current > report.lastReadTime ? userActiveSince.current : report.lastReadTime; - if ( - scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD || - !( - sortedVisibleReportActions && - _.some( - sortedVisibleReportActions, - (reportAction) => - newMessageTimeReference < reportAction.created && - (ReportActionsUtils.isReportPreviewAction(reportAction) ? reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID(), - ) - ) - ) { - return; - } - - Report.readNewestAction(report.reportID, false); - userActiveSince.current = DateUtils.getDBTime(); - lastReadTimeRef.current = newMessageTimeReference; - setCurrentUnreadMarker(null); - cacheUnreadMarkers.delete(report.reportID); - calculateUnreadMarker(); - }, [calculateUnreadMarker, report, sortedVisibleReportActions]); - - useEffect(() => { - const unsubscribeVisibilityListener = Visibility.onVisibilityChange(onVisibilityChange); - - return unsubscribeVisibilityListener; - }, [onVisibilityChange]); + }, [sortedVisibleReportActions, report.lastReadTime, report.reportID, messageManuallyMarkedUnread, shouldDisplayNewMarker, currentUnreadMarker]); const renderItem = useCallback( ({item: reportAction, index}) => (