Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function ReportActionsList({
const [isVisible, setIsVisible] = useState(Visibility.isVisible);
const isFocused = useIsFocused();

const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`);
const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID});

useEffect(() => {
Expand All @@ -183,7 +183,7 @@ function ReportActionsList({
const readActionSkipped = useRef(false);
const hasHeaderRendered = useRef(false);
const hasFooterRendered = useRef(false);
const linkedReportActionID = route?.params?.reportActionID ?? '-1';
const linkedReportActionID = route?.params?.reportActionID;

const lastAction = sortedVisibleReportActions.at(0);
const sortedVisibleReportActionsObjects: OnyxTypes.ReportActions = useMemo(
Expand Down Expand Up @@ -262,10 +262,8 @@ function ReportActionsList({
return true;
}

const isWithinVisibleThreshold = scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD ? message.created < (userActiveSince.current ?? '') : true;

// If the unread marker should be hidden or is not within the visible area, don't show the unread marker.
if (ReportActionsUtils.shouldHideNewMarker(message) || !isWithinVisibleThreshold) {
if (ReportActionsUtils.shouldHideNewMarker(message)) {
return false;
}

Expand Down
40 changes: 40 additions & 0 deletions tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,44 @@ describe('Unread Indicators', () => {
})
);
});

it('Move the new line indicator to the next message when the unread message is deleted', async () => {
let reportActions: OnyxEntry<ReportActions>;
const connection = Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`,
callback: (val) => (reportActions = val),
});
await signInAndGetAppWithUnreadChat();
await navigateToSidebarOption(0);

Report.addComment(REPORT_ID, 'Comment 1');

await waitForBatchedUpdates();

const firstNewReportAction = reportActions ? CollectionUtils.lastItem(reportActions) : undefined;

if (firstNewReportAction) {
Report.markCommentAsUnread(REPORT_ID, firstNewReportAction?.created);

await waitForBatchedUpdates();

Report.addComment(REPORT_ID, 'Comment 2');

await waitForBatchedUpdates();

Report.deleteReportComment(REPORT_ID, firstNewReportAction);

await waitForBatchedUpdates();
}

const secondNewReportAction = reportActions ? CollectionUtils.lastItem(reportActions) : undefined;

const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator');
const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText);
expect(unreadIndicator).toHaveLength(1);
const reportActionID = unreadIndicator.at(0)?.props?.['data-action-id'] as string;
expect(reportActionID).toBe(secondNewReportAction?.reportActionID);

Onyx.disconnect(connection);
});
});