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

[GH-47817]- remove messageManuallyMarkedUnread and manual handling of… #49367

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@
const userActiveSince = useRef<string>(DateUtils.getDBTime());
const lastMessageTime = useRef<string | null>(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}`);
Expand Down Expand Up @@ -211,7 +210,6 @@
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]);
Expand All @@ -224,16 +222,9 @@
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
Expand All @@ -245,19 +236,18 @@
}

return null;
}, [accountID, sortedVisibleReportActions, unreadMarkerTime, messageManuallyMarkedUnread]);
}, [accountID, sortedVisibleReportActions, unreadMarkerTime]);

Check warning on line 239 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has an unnecessary dependency: 'accountID'. Either exclude it or remove the dependency array

Check warning on line 239 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has an unnecessary dependency: 'accountID'. Either exclude it or remove the dependency array
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
}, [accountID, sortedVisibleReportActions, unreadMarkerTime]);
}, [sortedVisibleReportActions, unreadMarkerTime]);

Actually you should fix this


/**
* Subscribe to read/unread events and update our unreadMarkerTime
*/
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 () => {
Expand All @@ -283,7 +273,6 @@
}

setUnreadMarkerTime(mostRecentReportActionCreated);
setMessageManuallyMarkedUnread(0);

// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [sortedVisibleReportActions]);
Expand Down
Loading