Skip to content
Merged
Changes from all commits
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
16 changes: 13 additions & 3 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {AUTOSCROLL_TO_TOP_THRESHOLD} from '@components/InvertedFlatList/BaseInve
import {PersonalDetailsContext, usePersonalDetails} from '@components/OnyxListItemProvider';
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useIsAnonymousUser from '@hooks/useIsAnonymousUser';
import useLocalize from '@hooks/useLocalize';
import useNetworkWithOfflineStatus from '@hooks/useNetworkWithOfflineStatus';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -202,6 +203,7 @@ function ReportActionsList({
const shouldFocusToTopOnMount = useMemo(() => isTransactionThreadReport || isMoneyRequestOrInvoiceReport, [isMoneyRequestOrInvoiceReport, isTransactionThreadReport]);
const topReportAction = sortedVisibleReportActions.at(-1);
const [shouldScrollToEndAfterLayout, setShouldScrollToEndAfterLayout] = useState(shouldFocusToTopOnMount && !reportActionID);
const isAnonymousUser = useIsAnonymousUser();

useEffect(() => {
const unsubscribe = Visibility.onVisibilityChange(() => {
Expand Down Expand Up @@ -267,6 +269,10 @@ function ReportActionsList({
* The reportActionID the unread marker should display above
*/
const [unreadMarkerReportActionID, unreadMarkerReportActionIndex] = useMemo(() => {
if (isAnonymousUser) {
return [null, -1];
}

// If there are message that were received while offline,
// we can skip checking all messages later than the earliest received offline message.
const startIndex = earliestReceivedOfflineMessageIndex ?? 0;
Expand Down Expand Up @@ -296,13 +302,17 @@ function ReportActionsList({
}

return [null, -1];
}, [accountID, earliestReceivedOfflineMessageIndex, prevSortedVisibleReportActionsObjects, sortedVisibleReportActions, unreadMarkerTime]);
}, [accountID, isAnonymousUser, earliestReceivedOfflineMessageIndex, prevSortedVisibleReportActionsObjects, sortedVisibleReportActions, unreadMarkerTime]);
prevUnreadMarkerReportActionID.current = unreadMarkerReportActionID;

/**
* Subscribe to read/unread events and update our unreadMarkerTime
*/
useEffect(() => {
if (isAnonymousUser) {
return;
}

const unreadActionSubscription = DeviceEventEmitter.addListener(`unreadAction_${report.reportID}`, (newLastReadTime: string) => {
setUnreadMarkerTime(newLastReadTime);
userActiveSince.current = DateUtils.getDBTime();
Expand All @@ -315,7 +325,7 @@ function ReportActionsList({
unreadActionSubscription.remove();
readNewestActionSubscription.remove();
};
}, [report.reportID]);
}, [report.reportID, isAnonymousUser]);

/**
* When the user reads a new message as it is received, we'll push the unreadMarkerTime down to the timestamp of
Expand All @@ -324,7 +334,7 @@ function ReportActionsList({
* lastReadTime.
*/
useLayoutEffect(() => {
if (unreadMarkerReportActionID) {
if (isAnonymousUser || unreadMarkerReportActionID) {
return;
}

Expand Down
Loading