From 96788ebccb0f3648ac9be336c0e776798cbe4a7f Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Thu, 1 Jan 2026 04:21:44 +0300 Subject: [PATCH 01/13] fix: rename variables to prefix deprecated --- src/libs/ReportActionsUtils.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 60164e4052cc..33e36e2ed40a 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -86,8 +86,8 @@ Onyx.connect({ callback: (val) => (isNetworkOffline = val?.isOffline ?? false), }); -let currentUserAccountID: number | undefined; -let currentEmail = ''; +let deprecatedCurrentUserAccountID: number | undefined; +let deprecatedCurrentEmail = ''; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (value) => { @@ -96,8 +96,8 @@ Onyx.connect({ return; } - currentUserAccountID = value.accountID; - currentEmail = value?.email ?? ''; + deprecatedCurrentUserAccountID = value.accountID; + deprecatedCurrentEmail = value?.email ?? ''; }, }); @@ -381,7 +381,7 @@ function isWhisperActionTargetedToOthers(reportAction: OnyxInputOrEntry): reportAction is ReportAction { @@ -2155,14 +2155,14 @@ function didMessageMentionCurrentUser(reportAction: OnyxInputOrEntry'); + return accountIDsFromMessage.includes(deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID) || emailsFromMessage.includes(deprecatedCurrentEmail) || message.includes(''); } /** * Check if the current user is the requestor of the action */ function wasActionTakenByCurrentUser(reportAction: OnyxInputOrEntry): boolean { - return currentUserAccountID === reportAction?.actorAccountID; + return deprecatedCurrentUserAccountID === reportAction?.actorAccountID; } /** @@ -3257,7 +3257,7 @@ function getRemovedFromApprovalChainMessage(reportAction: OnyxEntry displayName ?? login ?? 'Unknown Submitter'); // eslint-disable-next-line @typescript-eslint/no-deprecated return translateLocal('workspaceActions.removedFromApprovalWorkflow', {submittersNames, count: submittersNames.length}); @@ -3431,7 +3431,7 @@ function getCardIssuedMessage({ const isExpensifyCardActive = isCardActive(expensifyCard); const expensifyCardLink = (expensifyCardLinkText: string) => shouldRenderHTML && isExpensifyCardActive ? `${expensifyCardLinkText}` : expensifyCardLinkText; - const isAssigneeCurrentUser = currentUserAccountID === assigneeAccountID; + const isAssigneeCurrentUser = deprecatedCurrentUserAccountID === assigneeAccountID; const companyCardLink = shouldRenderHTML && isAssigneeCurrentUser && companyCard ? `${translate('workspace.companyCards.companyCard')}` From 7e964b963080a99fa6c79e17368de0099521a0ee Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Thu, 1 Jan 2026 04:24:06 +0300 Subject: [PATCH 02/13] fix: update the params for current user email usage --- src/libs/ReportActionsUtils.ts | 6 ++---- src/libs/actions/Report.ts | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 33e36e2ed40a..38709a5b6a3f 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -87,7 +87,6 @@ Onyx.connect({ }); let deprecatedCurrentUserAccountID: number | undefined; -let deprecatedCurrentEmail = ''; Onyx.connect({ key: ONYXKEYS.SESSION, callback: (value) => { @@ -97,7 +96,6 @@ Onyx.connect({ } deprecatedCurrentUserAccountID = value.accountID; - deprecatedCurrentEmail = value?.email ?? ''; }, }); @@ -2151,11 +2149,11 @@ function getMentionedEmailsFromMessage(message: string) { return matches.map((match) => Str.removeSMSDomain(match[1].substring(1))); } -function didMessageMentionCurrentUser(reportAction: OnyxInputOrEntry) { +function didMessageMentionCurrentUser(reportAction: OnyxInputOrEntry, currentUserEmail: string) { const accountIDsFromMessage = getMentionedAccountIDsFromAction(reportAction); const message = getReportActionMessage(reportAction)?.html ?? ''; const emailsFromMessage = getMentionedEmailsFromMessage(message); - return accountIDsFromMessage.includes(deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID) || emailsFromMessage.includes(deprecatedCurrentEmail) || message.includes(''); + return accountIDsFromMessage.includes(deprecatedCurrentUserAccountID ?? CONST.DEFAULT_NUMBER_ID) || emailsFromMessage.includes(currentUserEmail) || message.includes(''); } /** diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 5a45120de261..af81cea826c5 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2035,13 +2035,13 @@ function deleteReportComment( ...optimisticLastReportData, }; - const didCommentMentionCurrentUser = ReportActionsUtils.didMessageMentionCurrentUser(reportAction); + const didCommentMentionCurrentUser = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentUserEmail); if (didCommentMentionCurrentUser && reportAction.created === report?.lastMentionedTime) { const reportActionsForReport = allReportActions?.[reportID]; const latestMentionedReportAction = Object.values(reportActionsForReport ?? {}).find( (action) => action.reportActionID !== reportAction.reportActionID && - ReportActionsUtils.didMessageMentionCurrentUser(action) && + ReportActionsUtils.didMessageMentionCurrentUser(action, currentUserEmail) && ReportActionsUtils.shouldReportActionBeVisible(action, action.reportActionID), ); optimisticReport.lastMentionedTime = latestMentionedReportAction?.created ?? null; From 8a42e1f10b98942dcd38167f608995c8fb7a82eb Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Thu, 1 Jan 2026 04:34:46 +0300 Subject: [PATCH 03/13] fix: add email param to deleteReportComment --- src/libs/actions/Report.ts | 1 + .../home/report/ContextMenu/PopoverReportActionContextMenu.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index af81cea826c5..fa68f7925b08 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1996,6 +1996,7 @@ function deleteReportComment( ancestors: Ancestor[], isReportArchived: boolean | undefined, isOriginalReportArchived: boolean | undefined, + currentUserEmail: string ) { const originalReportID = getOriginalReportID(reportID, reportAction); const reportActionID = reportAction.reportActionID; diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx index 968a684d3aed..60609b07ee24 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.tsx @@ -370,7 +370,7 @@ function PopoverReportActionContextMenu({ref}: PopoverReportActionContextMenuPro } else if (reportAction) { // eslint-disable-next-line @typescript-eslint/no-deprecated InteractionManager.runAfterInteractions(() => { - deleteReportComment(reportIDRef.current, reportAction, ancestorsRef.current, isReportArchived, isOriginalReportArchived); + deleteReportComment(reportIDRef.current, reportAction, ancestorsRef.current, isReportArchived, isOriginalReportArchived, email ?? ''); }); } From 2d12baba43e111755f607b75e642b262804626ce Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Thu, 1 Jan 2026 04:37:25 +0300 Subject: [PATCH 04/13] fix: update current email references --- src/libs/actions/Report.ts | 3 ++- src/pages/home/report/ReportActionItemMessageEdit.tsx | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index fa68f7925b08..88d4f4b10c65 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2173,6 +2173,7 @@ function editReportComment( textForNewComment: string, isOriginalReportArchived: boolean | undefined, isOriginalParentReportArchived: boolean | undefined, + currentUserEmail: string, videoAttributeCache?: Record, ) { const originalReportID = originalReport?.reportID; @@ -2206,7 +2207,7 @@ function editReportComment( // Delete the comment if it's empty if (!htmlForNewComment) { - deleteReportComment(originalReportID, originalReportAction, ancestors, isOriginalReportArchived, isOriginalParentReportArchived); + deleteReportComment(originalReportID, originalReportAction, ancestors, isOriginalReportArchived, isOriginalParentReportArchived, currentUserEmail); return; } diff --git a/src/pages/home/report/ReportActionItemMessageEdit.tsx b/src/pages/home/report/ReportActionItemMessageEdit.tsx index 1a3a10679ad3..98fa1603e82b 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.tsx +++ b/src/pages/home/report/ReportActionItemMessageEdit.tsx @@ -29,6 +29,7 @@ import useScrollBlocker from '@hooks/useScrollBlocker'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import {setShouldShowComposeInput} from '@libs/actions/Composer'; import {clearActive, isActive as isEmojiPickerActive, isEmojiPickerVisible} from '@libs/actions/EmojiPickerAction'; import {composerFocusKeepFocusOn} from '@libs/actions/InputFocus'; @@ -110,6 +111,7 @@ function ReportActionItemMessageEdit({ ref, }: ReportActionItemMessageEditProps) { const [preferredSkinTone = CONST.EMOJI_DEFAULT_SKIN_TONE] = useOnyx(ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, {canBeMissing: true}); + const {email} = useCurrentUserPersonalDetails(); const theme = useTheme(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -314,9 +316,9 @@ function ReportActionItemMessageEdit({ ReportActionContextMenu.showDeleteModal(originalReportID ?? reportID, action, true, deleteDraft, () => focusEditAfterCancelDelete(textInputRef.current)); return; } - editReportComment(originalReport, action, ancestors, trimmedNewDraft, isOriginalReportArchived, isOriginalParentReportArchived, Object.fromEntries(draftMessageVideoAttributeCache)); + editReportComment(originalReport, action, ancestors, trimmedNewDraft, isOriginalReportArchived, isOriginalParentReportArchived, email ?? '', Object.fromEntries(draftMessageVideoAttributeCache)); deleteDraft(); - }, [reportID, action, ancestors, deleteDraft, draft, originalReportID, isOriginalReportArchived, originalReport, isOriginalParentReportArchived, debouncedValidateCommentMaxLength]); + }, [reportID, action, ancestors, deleteDraft, draft, originalReportID, isOriginalReportArchived, originalReport, isOriginalParentReportArchived, debouncedValidateCommentMaxLength, email]); /** * @param emoji From a21541dd45380af7ec167b2ad87b3f0ca914fbc5 Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Thu, 1 Jan 2026 04:38:41 +0300 Subject: [PATCH 05/13] style: lint fixes --- src/libs/actions/Report.ts | 2 +- .../report/ReportActionItemMessageEdit.tsx | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 88d4f4b10c65..799ea68743a0 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1996,7 +1996,7 @@ function deleteReportComment( ancestors: Ancestor[], isReportArchived: boolean | undefined, isOriginalReportArchived: boolean | undefined, - currentUserEmail: string + currentUserEmail: string, ) { const originalReportID = getOriginalReportID(reportID, reportAction); const reportActionID = reportAction.reportActionID; diff --git a/src/pages/home/report/ReportActionItemMessageEdit.tsx b/src/pages/home/report/ReportActionItemMessageEdit.tsx index 98fa1603e82b..7a5f00e6ce76 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.tsx +++ b/src/pages/home/report/ReportActionItemMessageEdit.tsx @@ -16,6 +16,7 @@ import * as Expensicons from '@components/Icon/Expensicons'; import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; import Tooltip from '@components/Tooltip'; import useAncestors from '@hooks/useAncestors'; +import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useHandleExceedMaxCommentLength from '@hooks/useHandleExceedMaxCommentLength'; import useIsScrollLikelyLayoutTriggered from '@hooks/useIsScrollLikelyLayoutTriggered'; import useKeyboardState from '@hooks/useKeyboardState'; @@ -29,7 +30,6 @@ import useScrollBlocker from '@hooks/useScrollBlocker'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; -import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import {setShouldShowComposeInput} from '@libs/actions/Composer'; import {clearActive, isActive as isEmojiPickerActive, isEmojiPickerVisible} from '@libs/actions/EmojiPickerAction'; import {composerFocusKeepFocusOn} from '@libs/actions/InputFocus'; @@ -316,9 +316,30 @@ function ReportActionItemMessageEdit({ ReportActionContextMenu.showDeleteModal(originalReportID ?? reportID, action, true, deleteDraft, () => focusEditAfterCancelDelete(textInputRef.current)); return; } - editReportComment(originalReport, action, ancestors, trimmedNewDraft, isOriginalReportArchived, isOriginalParentReportArchived, email ?? '', Object.fromEntries(draftMessageVideoAttributeCache)); + editReportComment( + originalReport, + action, + ancestors, + trimmedNewDraft, + isOriginalReportArchived, + isOriginalParentReportArchived, + email ?? '', + Object.fromEntries(draftMessageVideoAttributeCache), + ); deleteDraft(); - }, [reportID, action, ancestors, deleteDraft, draft, originalReportID, isOriginalReportArchived, originalReport, isOriginalParentReportArchived, debouncedValidateCommentMaxLength, email]); + }, [ + reportID, + action, + ancestors, + deleteDraft, + draft, + originalReportID, + isOriginalReportArchived, + originalReport, + isOriginalParentReportArchived, + debouncedValidateCommentMaxLength, + email, + ]); /** * @param emoji From 93f50cada3126473600b0a5df88e117d0d8ac97f Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Thu, 1 Jan 2026 04:51:26 +0300 Subject: [PATCH 06/13] test: fix broken tests --- tests/actions/ReportTest.ts | 38 ++++++++++++++++--------------- tests/ui/UnreadIndicatorsTest.tsx | 4 ++-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 7ed8cff409aa..f1e87c41466d 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -509,7 +509,8 @@ describe('actions/Report', () => { .then(() => { rerender(report); // If the user deletes a comment that is before the last read - Report.deleteReportComment(REPORT_ID, {...reportActions[200]}, ancestors.current, undefined, undefined); + Report.deleteReportComment(REPORT_ID, {...reportActions[200]}, ancestors.current, undefined, undefined, ''); + Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, ''); return waitForBatchedUpdates(); }) .then(() => { @@ -528,7 +529,8 @@ describe('actions/Report', () => { rerender(report); // If the user deletes the last comment after the lastReadTime the lastMessageText will reflect the new last comment - Report.deleteReportComment(REPORT_ID, {...reportActions[400]}, ancestors.current, undefined, undefined); + Report.deleteReportComment(REPORT_ID, {...reportActions[400]}, ancestors.current, undefined, undefined, ''); + Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, ''); return waitForBatchedUpdates(); }) .then(() => { @@ -998,7 +1000,7 @@ describe('actions/Report', () => { }; const {result: ancestors, rerender} = renderHook(() => useAncestors(originalReport)); - Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Testing an edited comment', undefined, undefined); + Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, ''); await waitForBatchedUpdates(); @@ -1032,7 +1034,7 @@ describe('actions/Report', () => { }); rerender(originalReport); - Report.deleteReportComment(REPORT_ID, newReportAction, ancestors.current, undefined, undefined); + Report.deleteReportComment(REPORT_ID, newReportAction, ancestors.current, undefined, undefined, ''); await waitForBatchedUpdates(); expect(PersistedRequests.getAll().length).toBe(0); @@ -1080,7 +1082,7 @@ describe('actions/Report', () => { }; const {result: ancestors, rerender} = renderHook(() => useAncestors(originalReport)); - Report.editReportComment(originalReport, reportAction, ancestors.current, 'Testing an edited comment', undefined, undefined); + Report.editReportComment(originalReport, reportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, ''); await waitForBatchedUpdates(); @@ -1096,7 +1098,7 @@ describe('actions/Report', () => { }); rerender(originalReport); - Report.deleteReportComment(REPORT_ID, reportAction, ancestors.current, undefined, undefined); + Report.deleteReportComment(REPORT_ID, reportAction, ancestors.current, undefined, undefined, ''); await waitForBatchedUpdates(); expect(PersistedRequests.getAll().length).toBe(1); @@ -1145,7 +1147,7 @@ describe('actions/Report', () => { }), ); - Report.deleteReportComment(REPORT_ID, reportAction, [], undefined, undefined); + Report.deleteReportComment(REPORT_ID, reportAction, [], undefined, undefined, ''); jest.runOnlyPendingTimers(); await waitForBatchedUpdates(); @@ -1207,7 +1209,7 @@ describe('actions/Report', () => { }); }); - Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined); + Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined, ''); await waitForBatchedUpdates(); expect(PersistedRequests.getAll().length).toBe(0); @@ -1276,7 +1278,7 @@ describe('actions/Report', () => { }); }); - Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined); + Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined, ''); await waitForBatchedUpdates(); expect(PersistedRequests.getAll().length).toBe(0); @@ -1472,7 +1474,7 @@ describe('actions/Report', () => { }); }); - Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined); + Report.deleteReportComment(REPORT_ID, newReportAction, [], undefined, undefined, ''); await waitForBatchedUpdates(); expect(PersistedRequests.getAll().length).toBe(0); @@ -1556,7 +1558,7 @@ describe('actions/Report', () => { }); }); - Report.deleteReportComment(REPORT_ID, reportAction, [], undefined, undefined); + Report.deleteReportComment(REPORT_ID, reportAction, [], undefined, undefined, ''); await waitForBatchedUpdates(); expect(PersistedRequests.getAll().length).toBe(1); @@ -1604,7 +1606,7 @@ describe('actions/Report', () => { const {result: ancestors} = renderHook(() => useAncestors({reportID: REPORT_ID})); - Report.deleteReportComment(REPORT_ID, reportAction, ancestors.current, undefined, undefined); + Report.deleteReportComment(REPORT_ID, reportAction, ancestors.current, undefined, undefined, ''); expect(PersistedRequests.getAll().length).toBe(3); @@ -1642,7 +1644,7 @@ describe('actions/Report', () => { const originalReport = { reportID: REPORT_ID, }; - Report.editReportComment(originalReport, reportAction, [], 'Testing an edited comment', undefined, undefined); + Report.editReportComment(originalReport, reportAction, [], 'Testing an edited comment', undefined, undefined, ''); await waitForBatchedUpdates(); @@ -1680,9 +1682,9 @@ describe('actions/Report', () => { const {result: ancestors} = renderHook(() => useAncestors(originalReport)); - Report.editReportComment(originalReport, action, ancestors.current, 'value1', undefined, undefined); - Report.editReportComment(originalReport, action, ancestors.current, 'value2', undefined, undefined); - Report.editReportComment(originalReport, action, ancestors.current, 'value3', undefined, undefined); + Report.editReportComment(originalReport, action, ancestors.current, 'value1', undefined, undefined, ''); + Report.editReportComment(originalReport, action, ancestors.current, 'value2', undefined, undefined, ''); + Report.editReportComment(originalReport, action, ancestors.current, 'value3', undefined, undefined, ''); const requests = PersistedRequests?.getAll(); @@ -1733,8 +1735,8 @@ describe('actions/Report', () => { const {result: ancestors} = renderHook(() => useAncestors(report)); - Report.deleteReportComment(reportID, mentionAction, ancestors.current, undefined, undefined); - Report.deleteReportComment(reportID, mentionAction2, ancestors.current, undefined, undefined); + Report.deleteReportComment(reportID, mentionAction, ancestors.current, undefined, undefined, ''); + Report.deleteReportComment(reportID, mentionAction2, ancestors.current, undefined, undefined, ''); await waitForBatchedUpdates(); diff --git a/tests/ui/UnreadIndicatorsTest.tsx b/tests/ui/UnreadIndicatorsTest.tsx index 2931c138662d..850c5753422c 100644 --- a/tests/ui/UnreadIndicatorsTest.tsx +++ b/tests/ui/UnreadIndicatorsTest.tsx @@ -579,7 +579,7 @@ describe('Unread Indicators', () => { expect(screen.getAllByText('Current User Comment 1').at(0)).toBeOnTheScreen(); if (lastReportAction) { - deleteReportComment(REPORT_ID, lastReportAction, [], undefined, undefined); + deleteReportComment(REPORT_ID, lastReportAction, [], undefined, undefined, ''); } return waitForBatchedUpdates(); }) @@ -616,7 +616,7 @@ describe('Unread Indicators', () => { await waitForBatchedUpdates(); - deleteReportComment(REPORT_ID, firstNewReportAction, [], undefined, undefined); + deleteReportComment(REPORT_ID, firstNewReportAction, [], undefined, undefined, ''); await waitForBatchedUpdates(); } From bf1a777e88a142004e8feb038650fd2413ff0c54 Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Thu, 1 Jan 2026 04:55:21 +0300 Subject: [PATCH 07/13] refactor: rename variable --- src/libs/actions/Report.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 799ea68743a0..69e5bb1de8da 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1996,7 +1996,7 @@ function deleteReportComment( ancestors: Ancestor[], isReportArchived: boolean | undefined, isOriginalReportArchived: boolean | undefined, - currentUserEmail: string, + currentEmail: string, ) { const originalReportID = getOriginalReportID(reportID, reportAction); const reportActionID = reportAction.reportActionID; @@ -2036,13 +2036,13 @@ function deleteReportComment( ...optimisticLastReportData, }; - const didCommentMentionCurrentUser = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentUserEmail); + const didCommentMentionCurrentUser = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentEmail); if (didCommentMentionCurrentUser && reportAction.created === report?.lastMentionedTime) { const reportActionsForReport = allReportActions?.[reportID]; const latestMentionedReportAction = Object.values(reportActionsForReport ?? {}).find( (action) => action.reportActionID !== reportAction.reportActionID && - ReportActionsUtils.didMessageMentionCurrentUser(action, currentUserEmail) && + ReportActionsUtils.didMessageMentionCurrentUser(action, currentEmail) && ReportActionsUtils.shouldReportActionBeVisible(action, action.reportActionID), ); optimisticReport.lastMentionedTime = latestMentionedReportAction?.created ?? null; @@ -2173,7 +2173,7 @@ function editReportComment( textForNewComment: string, isOriginalReportArchived: boolean | undefined, isOriginalParentReportArchived: boolean | undefined, - currentUserEmail: string, + currentEmail: string, videoAttributeCache?: Record, ) { const originalReportID = originalReport?.reportID; @@ -2207,7 +2207,7 @@ function editReportComment( // Delete the comment if it's empty if (!htmlForNewComment) { - deleteReportComment(originalReportID, originalReportAction, ancestors, isOriginalReportArchived, isOriginalParentReportArchived, currentUserEmail); + deleteReportComment(originalReportID, originalReportAction, ancestors, isOriginalReportArchived, isOriginalParentReportArchived, currentEmail); return; } From b1d8c2d9d6af3adc97c4f3872ff6727ead215a1e Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Thu, 1 Jan 2026 05:07:58 +0300 Subject: [PATCH 08/13] test: add unit test --- tests/unit/ReportActionsUtilsTest.ts | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/unit/ReportActionsUtilsTest.ts b/tests/unit/ReportActionsUtilsTest.ts index b35fdf7c3236..817a2edc6260 100644 --- a/tests/unit/ReportActionsUtilsTest.ts +++ b/tests/unit/ReportActionsUtilsTest.ts @@ -1868,4 +1868,76 @@ describe('ReportActionsUtils', () => { expect(actual).toBe(expected); }); }); + + describe('didMessageMentionCurrentUser', () => { + const currentUserEmail = 'currentuser@example.com'; + const otherUserEmail = 'otheruser@example.com'; + const otherUserAccountID = 456; + + it('should return true when email matches', () => { + const reportAction: ReportAction = { + ...createRandomReportAction(0), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + message: [ + { + html: `@${currentUserEmail}`, + type: 'COMMENT', + text: `@${currentUserEmail}`, + }, + ], + originalMessage: { + html: `@${currentUserEmail}`, + whisperedTo: [], + mentionedAccountIDs: [], + }, + }; + + const result = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentUserEmail); + expect(result).toBe(true); + }); + + it('should return true when message includes mention-here', () => { + const reportAction: ReportAction = { + ...createRandomReportAction(0), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + message: [ + { + html: 'Hello ', + type: 'COMMENT', + text: 'Hello @here', + }, + ], + originalMessage: { + html: 'Hello ', + whisperedTo: [], + mentionedAccountIDs: [], + }, + }; + + const result = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentUserEmail); + expect(result).toBe(true); + }); + + it('should return false when user is not mentioned', () => { + const reportAction: ReportAction = { + ...createRandomReportAction(0), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + message: [ + { + html: `@${otherUserEmail}`, + type: 'COMMENT', + text: `@${otherUserEmail}`, + }, + ], + originalMessage: { + html: `@${otherUserEmail}`, + whisperedTo: [], + mentionedAccountIDs: [otherUserAccountID], + }, + }; + + const result = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentUserEmail); + expect(result).toBe(false); + }); + }); }); From 51aeb2ec25fa94d6d978a6b849b7ce44ddbab1da Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Thu, 1 Jan 2026 05:23:13 +0300 Subject: [PATCH 09/13] test: fix broken jest test --- tests/actions/ReportTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index f1e87c41466d..e55658b5c1e6 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -529,8 +529,8 @@ describe('actions/Report', () => { rerender(report); // If the user deletes the last comment after the lastReadTime the lastMessageText will reflect the new last comment - Report.deleteReportComment(REPORT_ID, {...reportActions[400]}, ancestors.current, undefined, undefined, ''); - Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, ''); + Report.deleteReportComment(REPORT_ID, {...reportActions[400]}, ancestors.current, undefined, undefined, USER_1_LOGIN); + Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, USER_1_LOGIN); return waitForBatchedUpdates(); }) .then(() => { From 4eb6d4e30b2de19367b6b54afa7d7d5c918852f9 Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Sat, 3 Jan 2026 23:51:34 +0530 Subject: [PATCH 10/13] test: added tests --- tests/unit/ReportActionsUtilsTest.ts | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/unit/ReportActionsUtilsTest.ts b/tests/unit/ReportActionsUtilsTest.ts index 839911a4822f..2a0abf0e5abd 100644 --- a/tests/unit/ReportActionsUtilsTest.ts +++ b/tests/unit/ReportActionsUtilsTest.ts @@ -1876,6 +1876,78 @@ describe('ReportActionsUtils', () => { }); }); + describe('didMessageMentionCurrentUser', () => { + const currentUserEmail = 'currentuser@example.com'; + const otherUserEmail = 'otheruser@example.com'; + const otherUserAccountID = 456; + + it('should return true when email matches', () => { + const reportAction: ReportAction = { + ...createRandomReportAction(0), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + message: [ + { + html: `@${currentUserEmail}`, + type: 'COMMENT', + text: `@${currentUserEmail}`, + }, + ], + originalMessage: { + html: `@${currentUserEmail}`, + whisperedTo: [], + mentionedAccountIDs: [], + }, + }; + + const result = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentUserEmail); + expect(result).toBe(true); + }); + + it('should return true when message includes mention-here', () => { + const reportAction: ReportAction = { + ...createRandomReportAction(0), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + message: [ + { + html: 'Hello ', + type: 'COMMENT', + text: 'Hello @here', + }, + ], + originalMessage: { + html: 'Hello ', + whisperedTo: [], + mentionedAccountIDs: [], + }, + }; + + const result = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentUserEmail); + expect(result).toBe(true); + }); + + it('should return false when user is not mentioned', () => { + const reportAction: ReportAction = { + ...createRandomReportAction(0), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + message: [ + { + html: `@${otherUserEmail}`, + type: 'COMMENT', + text: `@${otherUserEmail}`, + }, + ], + originalMessage: { + html: `@${otherUserEmail}`, + whisperedTo: [], + mentionedAccountIDs: [otherUserAccountID], + }, + }; + + const result = ReportActionsUtils.didMessageMentionCurrentUser(reportAction, currentUserEmail); + expect(result).toBe(false); + }); + }); + describe('getReportActionActorAccountID', () => { it('should return report owner account id if action is REPORTPREVIEW and report is a policy expense chat', () => { const reportAction: ReportAction = { From 944b2eb6ff0d0cbb881efbfaa5fb877e95a71606 Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Sat, 3 Jan 2026 23:53:18 +0530 Subject: [PATCH 11/13] test: fix broken test --- tests/actions/ReportTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index e55658b5c1e6..1d265bca6056 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -509,8 +509,8 @@ describe('actions/Report', () => { .then(() => { rerender(report); // If the user deletes a comment that is before the last read - Report.deleteReportComment(REPORT_ID, {...reportActions[200]}, ancestors.current, undefined, undefined, ''); - Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, ''); + Report.deleteReportComment(REPORT_ID, {...reportActions[200]}, ancestors.current, undefined, undefined, USER_1_LOGIN); + Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, USER_1_LOGIN); return waitForBatchedUpdates(); }) .then(() => { From 24a88d144dfd97087185a0ef92ce84fb9fc3edca Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Sun, 4 Jan 2026 00:08:13 +0530 Subject: [PATCH 12/13] fix: remove unwanted code --- tests/actions/ReportTest.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 1d265bca6056..89a2725e5649 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -510,7 +510,6 @@ describe('actions/Report', () => { rerender(report); // If the user deletes a comment that is before the last read Report.deleteReportComment(REPORT_ID, {...reportActions[200]}, ancestors.current, undefined, undefined, USER_1_LOGIN); - Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, USER_1_LOGIN); return waitForBatchedUpdates(); }) .then(() => { @@ -530,7 +529,6 @@ describe('actions/Report', () => { rerender(report); // If the user deletes the last comment after the lastReadTime the lastMessageText will reflect the new last comment Report.deleteReportComment(REPORT_ID, {...reportActions[400]}, ancestors.current, undefined, undefined, USER_1_LOGIN); - Report.deleteReportComment(REPORT_ID, {...reportActions[300]}, ancestors.current, undefined, undefined, USER_1_LOGIN); return waitForBatchedUpdates(); }) .then(() => { From ec51395adf8929d02e94c9031b77ed2fcfcb4b5b Mon Sep 17 00:00:00 2001 From: Manan Jadhav Date: Wed, 7 Jan 2026 02:47:17 +0530 Subject: [PATCH 13/13] test: added test for email param --- tests/actions/ReportTest.ts | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index f711ea035e9c..2071112bc4a2 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -1061,6 +1061,41 @@ describe('actions/Report', () => { TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.DELETE_COMMENT, 0); }); + it('should remove AddComment and UpdateComment without sending any request when DeleteComment is set with currentUserEmail', async () => { + global.fetch = TestHelper.getGlobalFetchMock(); + const TEST_USER_ACCOUNT_ID = 1; + const REPORT_ID = '1'; + const REPORT: OnyxTypes.Report = createRandomReport(1, undefined); + const created = format(addSeconds(subMinutes(new Date(), 10), 10), CONST.DATE.FNS_DB_FORMAT_STRING); + + Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}); + Report.addComment(REPORT, REPORT_ID, [], 'Testing a comment', CONST.DEFAULT_TIME_ZONE); + + const reportActionID = PersistedRequests.getAll().at(0)?.data?.reportActionID as string | undefined; + const newReportAction = TestHelper.buildTestReportComment(created, TEST_USER_ACCOUNT_ID, reportActionID); + const originalReport = {reportID: REPORT_ID}; + const {result: ancestors, rerender} = renderHook(() => useAncestors(originalReport)); + + const currentUserEmail = 'test@test.com'; + Report.editReportComment(originalReport, newReportAction, ancestors.current, 'Testing an edited comment', undefined, undefined, currentUserEmail); + await waitForBatchedUpdates(); + + const persistedRequests = await getOnyxValue(ONYXKEYS.PERSISTED_REQUESTS); + expect(persistedRequests?.at(0)?.command).toBe(WRITE_COMMANDS.ADD_COMMENT); + + rerender(originalReport); + Report.deleteReportComment(REPORT_ID, newReportAction, ancestors.current, undefined, undefined, currentUserEmail); + await waitForBatchedUpdates(); + + expect(PersistedRequests.getAll().length).toBe(0); + Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}); + await waitForBatchedUpdates(); + + TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.ADD_COMMENT, 0); + TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.UPDATE_COMMENT, 0); + TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.DELETE_COMMENT, 0); + }); + it('should send DeleteComment request and remove UpdateComment accordingly', async () => { global.fetch = TestHelper.getGlobalFetchMock(); @@ -1711,6 +1746,33 @@ describe('actions/Report', () => { TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.UPDATE_COMMENT, 1); }); + it('it should only send the last sequential UpdateComment request to BE with currentUserEmail', async () => { + global.fetch = TestHelper.getGlobalFetchMock(); + await Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}); + + const action: OnyxEntry = { + reportID: '123', + reportActionID: '722', + actionName: 'ADDCOMMENT', + created: '2024-10-21 10:37:59.881', + }; + const originalReport = {reportID: '123'}; + const {result: ancestors} = renderHook(() => useAncestors(originalReport)); + const currentUserEmail = 'user@test.com'; + + Report.editReportComment(originalReport, action, ancestors.current, 'value1', undefined, undefined, currentUserEmail); + Report.editReportComment(originalReport, action, ancestors.current, 'value2', undefined, undefined, currentUserEmail); + Report.editReportComment(originalReport, action, ancestors.current, 'value3', undefined, undefined, currentUserEmail); + + const requests = PersistedRequests?.getAll(); + expect(requests.length).toBe(1); + expect(requests?.at(0)?.command).toBe(WRITE_COMMANDS.UPDATE_COMMENT); + expect(requests?.at(0)?.data?.reportComment).toBe('value3'); + + await Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}); + TestHelper.expectAPICommandToHaveBeenCalled(WRITE_COMMANDS.UPDATE_COMMENT, 1); + }); + it('should clears lastMentionedTime when all mentions to the current user are deleted', async () => { const reportID = '1'; const mentionActionID = '1';