Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: archived reports are unable to mark as read #45240

Merged
merged 7 commits into from
Jul 29, 2024
34 changes: 23 additions & 11 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,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 @@ -264,13 +265,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 @@ -521,6 +526,10 @@ function ReportActionsList({
return;
}

if (hasCalledReadNewestAction.current) {
return;
}

if (!isVisible || !isFocused) {
if (!lastMessageTime.current) {
lastMessageTime.current = sortedVisibleReportActions[0]?.created ?? '';
Expand All @@ -532,24 +541,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);
Comment on lines +547 to +550
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Archived reports are always unread? are you sure this won't cause regression after we fix "Mark as unread" bug some day?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkhutornyi No this won't cause any regression. The reason is that this code will only be executed when we click on the LHN item. So if we fix the "Mark as unread" bug in future, it would mean that we will be able to right click on the LHN item and mark that as unread, which is irrespective of the changes here.

Also, since "Mark as unread" currently works for me, so I tested this PR and it works fine 👍

video.mp4

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
Loading