diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index ddadc8505854..c1c417e730d5 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1149,6 +1149,16 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry, key: return false; } + // Hide automatic TAKE_CONTROL actions created by OldDot's auto-pay workflow. + // When automaticAction is true and there are no mentionedAccountIDs, this indicates + // the TAKE_CONTROL was a side effect of auto-pay rather than a manual approver change. + if (actionName === CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL) { + const originalMessage = getOriginalMessage(reportAction as ReportAction); + if (originalMessage?.automaticAction && !originalMessage?.mentionedAccountIDs?.length) { + return false; + } + } + if (isWhisperActionTargetedToOthers(reportAction)) { return false; } diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index cc91471cb300..b72a89d1f09c 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -1296,6 +1296,8 @@ type OriginalMessageTakeControl = { lastModified: string; /** Tagged account IDs of new approvers */ mentionedAccountIDs: number[]; + /** Whether this action was triggered automatically (e.g., during auto-pay) */ + automaticAction?: boolean; }; /** diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index 4b04baaefaa0..736217db080c 100644 --- a/tests/unit/OptionsListUtilsTest.tsx +++ b/tests/unit/OptionsListUtilsTest.tsx @@ -4501,7 +4501,7 @@ describe('OptionsListUtils', () => { message: [{type: 'COMMENT', text: ''}], originalMessage: {}, }; - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { [takeControlAction.reportActionID]: takeControlAction, }); const lastMessage = getLastMessageTextForReport({ @@ -4522,7 +4522,7 @@ describe('OptionsListUtils', () => { message: [{type: 'COMMENT', text: ''}], originalMessage: {}, }; - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { [rerouteAction.reportActionID]: rerouteAction, }); const lastMessage = getLastMessageTextForReport({ diff --git a/tests/unit/ReportActionsUtilsTest.ts b/tests/unit/ReportActionsUtilsTest.ts index e82970f2a553..5eb5f9e4895c 100644 --- a/tests/unit/ReportActionsUtilsTest.ts +++ b/tests/unit/ReportActionsUtilsTest.ts @@ -1636,6 +1636,72 @@ describe('ReportActionsUtils', () => { const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); expect(actual).toBe(true); }); + + it('should return false for TAKE_CONTROL when automaticAction is true and mentionedAccountIDs is empty', () => { + const reportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, + reportActionID: '1', + created: '2025-09-29', + originalMessage: { + lastModified: '2025-09-29', + mentionedAccountIDs: [] as number[], + automaticAction: true, + }, + } as ReportAction; + + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); + expect(actual).toBe(false); + }); + + it('should return true for TAKE_CONTROL when automaticAction is true but mentionedAccountIDs has values', () => { + const reportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, + reportActionID: '1', + created: '2025-09-29', + message: [{html: 'took control', type: 'COMMENT', text: 'took control'}], + originalMessage: { + lastModified: '2025-09-29', + mentionedAccountIDs: [123], + automaticAction: true, + }, + } as ReportAction; + + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); + expect(actual).toBe(true); + }); + + it('should return true for TAKE_CONTROL when automaticAction is false', () => { + const reportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, + reportActionID: '1', + created: '2025-09-29', + message: [{html: 'took control', type: 'COMMENT', text: 'took control'}], + originalMessage: { + lastModified: '2025-09-29', + mentionedAccountIDs: [] as number[], + automaticAction: false, + }, + } as ReportAction; + + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); + expect(actual).toBe(true); + }); + + it('should return true for TAKE_CONTROL when automaticAction is not set', () => { + const reportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, + reportActionID: '1', + created: '2025-09-29', + message: [{html: 'took control', type: 'COMMENT', text: 'took control'}], + originalMessage: { + lastModified: '2025-09-29', + mentionedAccountIDs: [456], + }, + } as ReportAction; + + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); + expect(actual).toBe(true); + }); }); describe('getPolicyChangeLogUpdateEmployee', () => {