From 942876f4e3ac28cdfa14a85436afaa52a18f9ddb Mon Sep 17 00:00:00 2001 From: Klajdi Paja Date: Mon, 16 Sep 2024 15:52:45 +0200 Subject: [PATCH 1/2] [GH-47817]- remove messageManuallyMarkedUnread and manual handling of the unread marker so that we rely on the BE information about the last unread action --- src/pages/home/report/ReportActionsList.tsx | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 6828e10e7e3b..cbe15b88154d 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -167,7 +167,6 @@ function ReportActionsList({ const userActiveSince = useRef(DateUtils.getDBTime()); const lastMessageTime = useRef(null); const [isVisible, setIsVisible] = useState(Visibility.isVisible()); - const [messageManuallyMarkedUnread, setMessageManuallyMarkedUnread] = useState(0); const isFocused = useIsFocused(); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`); @@ -211,7 +210,6 @@ function ReportActionsList({ const [unreadMarkerTime, setUnreadMarkerTime] = useState(report.lastReadTime ?? ''); useEffect(() => { setUnreadMarkerTime(report.lastReadTime ?? ''); - setMessageManuallyMarkedUnread(0); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [report.reportID]); @@ -224,16 +222,9 @@ function ReportActionsList({ const nextMessage = sortedVisibleReportActions[index + 1]; const isCurrentMessageUnread = isMessageUnread(reportAction, unreadMarkerTime); const isNextMessageRead = !nextMessage || !isMessageUnread(nextMessage, unreadMarkerTime); - let shouldDisplay = isCurrentMessageUnread && isNextMessageRead && !ReportActionsUtils.shouldHideNewMarker(reportAction); - - if (shouldDisplay && !messageManuallyMarkedUnread) { - // Prevent displaying a new marker line when report action is of type "REPORT_PREVIEW" and last actor is the current user - const isFromCurrentUser = accountID === (ReportActionsUtils.isReportPreviewAction(reportAction) ? !reportAction.childLastActorAccountID : reportAction.actorAccountID); - const isWithinVisibleThreshold = scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD ? reportAction.created < (userActiveSince.current ?? '') : true; - shouldDisplay = !isFromCurrentUser && isWithinVisibleThreshold; - } - - return shouldDisplay; + const shouldDisplay = isCurrentMessageUnread && isNextMessageRead && !ReportActionsUtils.shouldHideNewMarker(reportAction); + const isWithinVisibleThreshold = scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD ? reportAction.created < (userActiveSince.current ?? '') : true; + return shouldDisplay && isWithinVisibleThreshold; }; // Scan through each visible report action until we find the appropriate action to show the unread marker @@ -245,7 +236,7 @@ function ReportActionsList({ } return null; - }, [accountID, sortedVisibleReportActions, unreadMarkerTime, messageManuallyMarkedUnread]); + }, [accountID, sortedVisibleReportActions, unreadMarkerTime]); /** * Subscribe to read/unread events and update our unreadMarkerTime @@ -253,11 +244,10 @@ function ReportActionsList({ useEffect(() => { const unreadActionSubscription = DeviceEventEmitter.addListener(`unreadAction_${report.reportID}`, (newLastReadTime: string) => { setUnreadMarkerTime(newLastReadTime); - setMessageManuallyMarkedUnread(new Date().getTime()); + userActiveSince.current = DateUtils.getDBTime(); }); const readNewestActionSubscription = DeviceEventEmitter.addListener(`readNewestAction_${report.reportID}`, (newLastReadTime: string) => { setUnreadMarkerTime(newLastReadTime); - setMessageManuallyMarkedUnread(0); }); return () => { @@ -283,7 +273,6 @@ function ReportActionsList({ } setUnreadMarkerTime(mostRecentReportActionCreated); - setMessageManuallyMarkedUnread(0); // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, [sortedVisibleReportActions]); From 3fce21f0545601a5a1e2779bc0697a00e204f88e Mon Sep 17 00:00:00 2001 From: Klajdi Paja Date: Thu, 19 Sep 2024 10:46:09 +0200 Subject: [PATCH 2/2] remove accountID from memo to fix warning for useMemo has an unnecessary dependency --- src/pages/home/report/ReportActionsList.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index cbe15b88154d..29f86bba4a0d 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -170,7 +170,6 @@ function ReportActionsList({ const isFocused = useIsFocused(); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`); - const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID ?? 0}); useEffect(() => { const unsubscriber = Visibility.onVisibilityChange(() => { @@ -236,7 +235,7 @@ function ReportActionsList({ } return null; - }, [accountID, sortedVisibleReportActions, unreadMarkerTime]); + }, [sortedVisibleReportActions, unreadMarkerTime]); /** * Subscribe to read/unread events and update our unreadMarkerTime