Skip to content

Commit

Permalink
Merge pull request #54233 from bernhardoj/fix/53830-inconsistent-beha…
Browse files Browse the repository at this point in the history
…vior-when-deleting-unread-message
  • Loading branch information
blimpich authored Dec 23, 2024
2 parents 126d92a + e25e32f commit 9a0e1fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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 @@ -184,7 +184,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 @@ -263,10 +263,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);
});
});

0 comments on commit 9a0e1fc

Please sign in to comment.