diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 36ac445a78d4..e60076613ca5 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -934,7 +934,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[] = [ @@ -957,12 +957,16 @@ function readNewestAction(reportID: string, shouldEmitEvent = true) { lastReadTime, }; +<<<<<<< HEAD API.write('ReadNewestAction', parameters, {optimisticData}); if (!shouldEmitEvent) { return; } +======= + API.write(WRITE_COMMANDS.READ_NEWEST_ACTION, parameters, {optimisticData}); +>>>>>>> b2e1e21 (Merge pull request #35308 from Expensify/vit-revert34537) 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}) => (