Skip to content

Commit

Permalink
Merge pull request #45240 from callstack-internal/hur/fix-45228
Browse files Browse the repository at this point in the history
fix: archived reports are unable to mark as read
  • Loading branch information
grgia authored Jul 29, 2024
2 parents 66ebb3e + 90d3160 commit c16efbc
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ function ReportActionsList({
const userActiveSince = useRef<string | null>(null);
const lastMessageTime = useRef<string | null>(null);

const [isVisible, setIsVisible] = useState(false);
const [isVisible, setIsVisible] = useState(Visibility.isVisible());
const hasCalledReadNewestAction = useRef(false);
const isFocused = useIsFocused();

useEffect(() => {
Expand Down Expand Up @@ -267,13 +268,17 @@ 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.
// To handle this, we use the 'referrer' parameter to check if the current navigation is triggered from a notification.
const isFromNotification = route?.params?.referrer === CONST.REFERRER.NOTIFICATION;
if ((Visibility.isVisible() || isFromNotification) && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) {
Report.readNewestAction(report.reportID);
hasCalledReadNewestAction.current = true;
if (isFromNotification) {
Navigation.setParams({referrer: undefined});
}
Expand Down Expand Up @@ -524,6 +529,10 @@ function ReportActionsList({
return;
}

if (hasCalledReadNewestAction.current) {
return;
}

if (!isVisible || !isFocused) {
if (!lastMessageTime.current) {
lastMessageTime.current = sortedVisibleReportActions[0]?.created ?? '';
Expand All @@ -535,24 +544,27 @@ 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 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, we will mark the report as read.
*/
const isArchivedReport = ReportUtils.isArchivedRoom(report);
const isUnread = isArchivedReport || (newMessageTimeReference && newMessageTimeReference < reportAction.created);
return (
isUnread && (ReportActionsUtils.isReportPreviewAction(reportAction) ? reportAction.childLastActorAccountID : reportAction.actorAccountID) !== Report.getCurrentUserAccountID()
);
});
if (scrollingVerticalOffset.current >= MSG_VISIBLE_THRESHOLD || !areSomeReportActionsUnread) {
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).
Expand Down

0 comments on commit c16efbc

Please sign in to comment.