diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 4211061e3d91..e31297b0bb92 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -182,7 +182,7 @@ function getReportActionMessage(reportAction: PartialReportAction) { } function isDeletedParentAction(reportAction: OnyxInputOrEntry): boolean { - return (getReportActionMessage(reportAction)?.isDeletedParentAction ?? false) && (reportAction?.childVisibleActionCount ?? 0) > 0; + return isMessageDeleted(reportAction) && (reportAction?.childVisibleActionCount ?? 0) > 0; } function isReversedTransaction(reportAction: OnyxInputOrEntry) { @@ -1136,7 +1136,13 @@ function getIOUReportIDFromReportActionPreview(reportAction: OnyxEntry): boolean { - return getReportActionMessage(reportAction)?.isDeletedParentAction ?? false; + const message = getReportActionMessage(reportAction); + const originalMessage = getOriginalMessage(reportAction) as Message; + + return (message?.deleted != null && message?.deleted != "") || + (message?.isDeletedParentAction ?? false) || + (originalMessage?.deleted != null && originalMessage?.deleted != "") || + (originalMessage?.isDeletedParentAction ?? false) } /** @@ -1583,6 +1589,9 @@ function getReportActionMessageFragments(action: ReportAction): Message[] { const actionMessage = action.previousMessage ?? action.message; if (Array.isArray(actionMessage)) { + if (actionMessage?.length === 1) { + return [{...actionMessage[0], isDeletedParentAction: isMessageDeleted(action) } as Message] + } return actionMessage.filter((item): item is Message => !!item); } return actionMessage ? [actionMessage] : []; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 77b71f72031a..9ed5bc185dca 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -183,6 +183,7 @@ import { isForwardedAction, isIntegrationMessageAction, isMarkAsClosedAction, + isMessageDeleted, isModifiedExpenseAction, isMoneyRequestAction, isOldDotReportAction, @@ -1318,7 +1319,7 @@ function isIOUReport(reportOrID: OnyxInputOrEntry | SearchReport | strin * Checks if a report is an IOU report using report */ function isIOUReportUsingReport(report: OnyxEntry): report is Report { - return report?.type === CONST.REPORT.TYPE.IOU; + return report?.type === CONST.REPORT.TYPE.IOU; } /** * Checks if a report is a task report. @@ -4649,7 +4650,8 @@ function getReportName( const canUseDerivedValue = report && policy === undefined && parentReportActionParam === undefined && personalDetails === undefined && invoiceReceiverPolicy === undefined; const attributes = reportAttributesParam ?? reportAttributes; const derivedNameExists = report && !!attributes?.[report.reportID]?.reportName; - if (canUseDerivedValue && derivedNameExists) { + // This doesn't apply to chat reports because last message (report name) can be changed and/or edited + if (canUseDerivedValue && derivedNameExists && !isChatReport(report)) { return attributes[report.reportID].reportName; } return getReportNameInternal({report, policy, parentReportActionParam, personalDetails, invoiceReceiverPolicy}); @@ -4662,6 +4664,19 @@ function getSearchReportName(props: GetReportNameParams): string { } return getReportNameInternal(props); } +function isChatThreadDeleted(report: OnyxInputOrEntry, reportActionParam: OnyxInputOrEntry): boolean + { + if (!isChatThread(report)) { + return false + } + + let reportAction = reportActionParam as OnyxEntry + if (!reportAction) { + reportAction = getReportAction(report?.parentReportID, report?.parentReportActionID); + } + + return isMessageDeleted(reportAction) + } function getInvoiceReportName(report: OnyxEntry, policy?: OnyxEntry, invoiceReceiverPolicy?: OnyxEntry): string { const moneyRequestReportName = getMoneyRequestReportName({report, policy, invoiceReceiverPolicy}); @@ -4800,7 +4815,7 @@ function getReportNameInternal({ return getRenamedAction(parentReportAction, isExpenseReport(getReport(report.parentReportID, allReports))); } - if (parentReportActionMessage?.isDeletedParentAction) { + if (isChatThreadDeleted(report, parentReportActionParam)) { return translateLocal('parentReportAction.deletedMessage'); } @@ -10948,6 +10963,7 @@ export { isChatRoom, isTripRoom, isChatThread, + isChatThreadDeleted, isChildReport, isClosedExpenseReportWithNoExpenses, isCompletedTaskReport, diff --git a/tests/unit/ReportActionsUtilsTest.ts b/tests/unit/ReportActionsUtilsTest.ts index 8452950ed521..443f5e9eee14 100644 --- a/tests/unit/ReportActionsUtilsTest.ts +++ b/tests/unit/ReportActionsUtilsTest.ts @@ -9,6 +9,7 @@ import createRandomReport from '../utils/collections/reports'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; +import { isMessageDeleted } from '../../src/libs/ReportActionsUtils'; jest.mock('@components/ConfirmedRoute.tsx'); @@ -696,6 +697,108 @@ describe('ReportActionsUtils', () => { }); }); + describe('isMessageDeleted', () => { + it('should return true if there is property deleted inside message', () => { + const reportAction = { + created: '2025-05-12 17:27:01.825', + reportActionID: '8401445780099176', + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + originalMessage: { + html: 'Hello world', + whisperedTo: [] + }, + message: [ + { + html: 'Hello world', + deleted: '2025-05-12 17:37:01.825', + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '' + }, + ], + }; + expect(isMessageDeleted(reportAction)).toBeTruthy(); + }) + it('should return true if there is property isDeletedParentAction inside message', () => { + const reportAction = { + created: '2025-05-12 17:27:01.825', + reportActionID: '8401445780099176', + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + originalMessage: { + html: 'Hello world', + whisperedTo: [] + }, + message: [ + { + html: 'Hello world', + isDeletedParentAction: true, + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '' + }, + ], + }; + expect(isMessageDeleted(reportAction)).toBeTruthy(); + }) + it('should return true if there is property deleted inside original message', () => { + const reportAction = { + created: '2025-05-12 17:27:01.825', + reportActionID: '8401445780099176', + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + originalMessage: { + html: 'Hello world', + whisperedTo: [], + deleted: '2025-05-12 17:37:01.825' + }, + message: [ + { + html: 'Hello world', + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '' + }, + ], + }; + expect(isMessageDeleted(reportAction)).toBeTruthy(); + }) + it('should return true if there is property isDeletedParentAction inside original message', () => { + const reportAction = { + created: '2025-05-12 17:27:01.825', + reportActionID: '8401445780099176', + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + originalMessage: { + html: 'Hello world', + whisperedTo: [], + isDeletedParentAction: true + }, + message: [ + { + html: 'Hello world', + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '' + }, + ], + }; + expect(isMessageDeleted(reportAction)).toBeTruthy(); + }) + it('should return false if there are no deletion properties in message and originalMessage', () => { + const reportAction = { + created: '2025-05-12 17:27:01.825', + reportActionID: '8401445780099176', + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + originalMessage: { + html: 'Hello world', + whisperedTo: [] + }, + message: [ + { + html: 'Hello world', + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '' + }, + ], + }; + expect(isMessageDeleted(reportAction)).toBeFalsy(); + }) + }) + describe('getReportActionMessageFragments', () => { it('should return the correct fragment for the REIMBURSED action', () => { const action = { @@ -734,6 +837,22 @@ describe('ReportActionsUtils', () => { const expectedFragments = ReportActionsUtils.getReportActionMessageFragments(action); expect(expectedFragments).toEqual([{text: expectedMessage, html: `${expectedMessage}`, type: 'COMMENT'}]); }); + it('should return the correct fragment for the deleted message', () => { + const action = { + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + reportActionID: '1', + created: '1', + message: [ + { + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '', + deleted: '2025-05-12 17:27:01.825' + } + ], + }; + const expectedFragments = ReportActionsUtils.getReportActionMessageFragments(action); + expect(expectedFragments).toEqual([{text: '', type: CONST.REPORT.MESSAGE.TYPE.COMMENT, isDeletedParentAction: true, deleted: '2025-05-12 17:27:01.825'}]); + }); }); describe('shouldShowAddMissingDetails', () => { diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 5b8ea7de38dc..83ba1580f7a5 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -449,6 +449,52 @@ describe('ReportUtils', () => { ).toBe('floki@vikings.net'); }); + test('with deleted message and provided parent action param', () => { + const report = { + type: CONST.REPORT.TYPE.CHAT, + reportID: '4401445780099175', + parentReportActionID: '8401445780099176', + parentReportID: '4401445780099175' + } + const reportAction = { + created: '2025-05-12 17:27:01.825', + reportActionID: '8401445780099176', + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + message: [ + { + deleted: '2025-05-12 17:27:01.825', + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '' + } + ] + } + expect(getReportName(report, undefined, reportAction)).toEqual(translateLocal('parentReportAction.deletedMessage')); + }); + + test('with deleted message and not provided parent action param', async () => { + const report = { + type: CONST.REPORT.TYPE.CHAT, + parentReportActionID: '8401445780099176', + parentReportID: '4401445780099175', + reportID: '2401445780099174' + } + const reportAction = { + reportActionID: '8401445780099176', + parentReportID: '', + message: [ + { + deleted: '2025-05-12 17:27:01.825', + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + text: '' + } + ] + } + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, { + [reportAction.reportActionID]: reportAction + }) + expect(getReportName(report)).toEqual(translateLocal('parentReportAction.deletedMessage')); + }); + test('SMS', () => { expect( getReportName({