From e24a9176a0ecf7007c99d595106a6f17e8fd7fea Mon Sep 17 00:00:00 2001 From: hurali97 Date: Thu, 11 Jul 2024 14:29:38 +0500 Subject: [PATCH 1/4] fix: archived reports are unable to mark as read --- src/pages/home/report/ReportActionsList.tsx | 32 ++++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 1ea58028c69f..5e06659e1d62 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -171,7 +171,8 @@ function ReportActionsList({ const userActiveSince = useRef(null); const lastMessageTime = useRef(null); - const [isVisible, setIsVisible] = useState(false); + const [isVisible, setIsVisible] = useState(Visibility.isVisible()); + const hasCalledReadNewestAction = useRef(false); const isFocused = useIsFocused(); useEffect(() => { @@ -261,6 +262,9 @@ function ReportActionsList({ if (!userActiveSince.current || report.reportID !== prevReportID) { return; } + if (hasCalledReadNewestAction.current) { + return; + } if (ReportUtils.isUnread(report)) { // On desktop, when the notification center is displayed, Visibility.isVisible() will return false. // Currently, there's no programmatic way to dismiss the notification center panel. @@ -269,6 +273,7 @@ function ReportActionsList({ if ((Visibility.isVisible() || isFromNotification) && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { Report.readNewestAction(report.reportID); Navigation.setParams({referrer: undefined}); + hasCalledReadNewestAction.current = true; } else { readActionSkipped.current = true; } @@ -516,6 +521,10 @@ function ReportActionsList({ return; } + if (hasCalledReadNewestAction.current) { + return; + } + if (!isVisible || !isFocused) { if (!lastMessageTime.current) { lastMessageTime.current = sortedVisibleReportActions[0]?.created ?? ''; @@ -527,24 +536,25 @@ function ReportActionsList({ // show marker based on report.lastReadTime const newMessageTimeReference = lastMessageTime.current && report.lastReadTime && lastMessageTime.current > report.lastReadTime ? userActiveSince.current : report.lastReadTime; lastMessageTime.current = null; - if ( - scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD || - !sortedVisibleReportActions.some( - (reportAction) => - newMessageTimeReference && - newMessageTimeReference < reportAction.created && - (ReportActionsUtils.isReportPreviewAction(reportAction) ? reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID(), - ) - ) { + const isSome = sortedVisibleReportActions.some((reportAction) => { + const isTimeLesserOrEqual = ReportUtils.isArchivedRoom(report) + ? newMessageTimeReference && newMessageTimeReference <= reportAction.created + : newMessageTimeReference && newMessageTimeReference < reportAction.created; + return ( + isTimeLesserOrEqual && + (ReportActionsUtils.isReportPreviewAction(reportAction) ? reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID() + ); + }); + if (scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD || !isSome) { return; } - Report.readNewestAction(report.reportID); userActiveSince.current = DateUtils.getDBTime(); lastReadTimeRef.current = newMessageTimeReference; setCurrentUnreadMarker(null); cacheUnreadMarkers.delete(report.reportID); calculateUnreadMarker(); + hasCalledReadNewestAction.current = true; // This effect logic to `mark as read` will only run when the report focused has new messages and the App visibility // is changed to visible(meaning user switched to app/web, while user was previously using different tab or application). From 29665f7c6784379e7b41b658ed480ae872bff048 Mon Sep 17 00:00:00 2001 From: hurali97 Date: Thu, 11 Jul 2024 14:41:59 +0500 Subject: [PATCH 2/4] refactor: renamve variable and add comments --- src/pages/home/report/ReportActionsList.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 5e06659e1d62..5ae633a00b4c 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -536,7 +536,12 @@ function ReportActionsList({ // show marker based on report.lastReadTime const newMessageTimeReference = lastMessageTime.current && report.lastReadTime && lastMessageTime.current > report.lastReadTime ? userActiveSince.current : report.lastReadTime; lastMessageTime.current = null; - const isSome = sortedVisibleReportActions.some((reportAction) => { + const areSomeReportActionsUnread = sortedVisibleReportActions.some((reportAction) => { + /** + * In case of archived reports, we have `newMessageTimeReference` equal to `reportAction.created`. + * So the condition should be `<=` to mark the report as read. We will only use this condition when + * the report is archived to not introduce any regression for other reports. + */ const isTimeLesserOrEqual = ReportUtils.isArchivedRoom(report) ? newMessageTimeReference && newMessageTimeReference <= reportAction.created : newMessageTimeReference && newMessageTimeReference < reportAction.created; @@ -545,7 +550,7 @@ function ReportActionsList({ (ReportActionsUtils.isReportPreviewAction(reportAction) ? reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID() ); }); - if (scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD || !isSome) { + if (scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD || !areSomeReportActionsUnread) { return; } Report.readNewestAction(report.reportID); From b396f145370d3cbb182b75a34e20e6bb1d635953 Mon Sep 17 00:00:00 2001 From: hurali97 Date: Fri, 19 Jul 2024 12:55:17 +0500 Subject: [PATCH 3/4] fix: update condition to mark archived chats as read --- src/pages/home/report/ReportActionsList.tsx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index ba867c6feb17..47f6a918ae1f 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -541,16 +541,13 @@ function ReportActionsList({ lastMessageTime.current = null; const areSomeReportActionsUnread = sortedVisibleReportActions.some((reportAction) => { /** - * In case of archived reports, we have `newMessageTimeReference` equal to `reportAction.created`. - * So the condition should be `<=` to mark the report as read. We will only use this condition when - * the report is archived to not introduce any regression for other reports. + * The archived reports should not be marked as unread. So we are checking if the report is archived or not. + * If the report is archived and unread, we will mark the report as read. */ - const isTimeLesserOrEqual = ReportUtils.isArchivedRoom(report) - ? newMessageTimeReference && newMessageTimeReference <= reportAction.created - : newMessageTimeReference && newMessageTimeReference < reportAction.created; + const isUnreadArchivedReport = ReportUtils.isArchivedRoom(report) && ReportUtils.isUnread(report); + const isUnread = isUnreadArchivedReport || (newMessageTimeReference && newMessageTimeReference < reportAction.created); return ( - isTimeLesserOrEqual && - (ReportActionsUtils.isReportPreviewAction(reportAction) ? reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID() + isUnread && (ReportActionsUtils.isReportPreviewAction(reportAction) ? reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID() ); }); if (scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD || !areSomeReportActionsUnread) { From 90d31601cb5cff83a6558eda5fb7eae3b1166d78 Mon Sep 17 00:00:00 2001 From: hurali97 Date: Tue, 23 Jul 2024 14:39:44 +0500 Subject: [PATCH 4/4] fix: mark archived reports as read --- src/pages/home/report/ReportActionsList.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index f93798b16b28..fa5a06f618df 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -544,10 +544,10 @@ function ReportActionsList({ const areSomeReportActionsUnread = sortedVisibleReportActions.some((reportAction) => { /** * The archived reports should not be marked as unread. So we are checking if the report is archived or not. - * If the report is archived and unread, we will mark the report as read. + * If the report is archived, we will mark the report as read. */ - const isUnreadArchivedReport = ReportUtils.isArchivedRoom(report) && ReportUtils.isUnread(report); - const isUnread = isUnreadArchivedReport || (newMessageTimeReference && newMessageTimeReference < reportAction.created); + const isArchivedReport = ReportUtils.isArchivedRoom(report); + const isUnread = isArchivedReport || (newMessageTimeReference && newMessageTimeReference < reportAction.created); return ( isUnread && (ReportActionsUtils.isReportPreviewAction(reportAction) ? reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID() );