diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 4ac46fcf212e..a7812bacbde2 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -932,6 +932,7 @@ function readNewestAction(reportID: string) { }; API.write('ReadNewestAction', parameters, {optimisticData}); + DeviceEventEmitter.emit(`readNewestAction_${reportID}`, lastReadTime); } /** diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 2009dc9a102d..fe054ecc462c 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -144,7 +144,7 @@ function ReportActionsList({ const route = useRoute(); const opacity = useSharedValue(0); const userActiveSince = useRef(null); - const unreadActionSubscription = useRef(null); + const markerInit = () => { if (!cacheUnreadMarkers.has(report.reportID)) { return null; @@ -236,20 +236,26 @@ function ReportActionsList({ }, [report.lastReadTime, report.reportID]); useEffect(() => { - // If the reportID changes, we reset the userActiveSince to null, we need to do it because - // this component doesn't unmount when the reportID changes - if (unreadActionSubscription.current) { - unreadActionSubscription.current.remove(); - unreadActionSubscription.current = null; - } - - // Listen to specific reportID for unread event and set the marker to new message - unreadActionSubscription.current = DeviceEventEmitter.addListener(`unreadAction_${report.reportID}`, (newLastReadTime) => { + const resetUnreadMarker = (newLastReadTime) => { cacheUnreadMarkers.delete(report.reportID); lastReadTimeRef.current = newLastReadTime; setCurrentUnreadMarker(null); + }; + + const unreadActionSubscription = DeviceEventEmitter.addListener(`unreadAction_${report.reportID}`, (newLastReadTime) => { + resetUnreadMarker(newLastReadTime); setMessageManuallyMarkedUnread(new Date().getTime()); }); + + const readNewestActionSubscription = DeviceEventEmitter.addListener(`readNewestAction_${report.reportID}`, (newLastReadTime) => { + resetUnreadMarker(newLastReadTime); + setMessageManuallyMarkedUnread(0); + }); + + return () => { + unreadActionSubscription.remove(); + readNewestActionSubscription.remove(); + }; }, [report.reportID]); useEffect(() => {