Skip to content
Closed
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
13 changes: 11 additions & 2 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function getReportActionMessage(reportAction: PartialReportAction) {
}

function isDeletedParentAction(reportAction: OnyxInputOrEntry<ReportAction>): boolean {
return (getReportActionMessage(reportAction)?.isDeletedParentAction ?? false) && (reportAction?.childVisibleActionCount ?? 0) > 0;
return isMessageDeleted(reportAction) && (reportAction?.childVisibleActionCount ?? 0) > 0;
}

function isReversedTransaction(reportAction: OnyxInputOrEntry<ReportAction | OptimisticIOUReportAction>) {
Expand Down Expand Up @@ -1136,7 +1136,13 @@ function getIOUReportIDFromReportActionPreview(reportAction: OnyxEntry<ReportAct
* A helper method to identify if the message is deleted or not.
*/
function isMessageDeleted(reportAction: OnyxInputOrEntry<ReportAction>): 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)
}

/**
Expand Down Expand Up @@ -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] : [];
Expand Down
22 changes: 19 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ import {
isForwardedAction,
isIntegrationMessageAction,
isMarkAsClosedAction,
isMessageDeleted,
isModifiedExpenseAction,
isMoneyRequestAction,
isOldDotReportAction,
Expand Down Expand Up @@ -1318,7 +1319,7 @@ function isIOUReport(reportOrID: OnyxInputOrEntry<Report> | SearchReport | strin
* Checks if a report is an IOU report using report
*/
function isIOUReportUsingReport(report: OnyxEntry<Report>): 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.
Expand Down Expand Up @@ -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});
Expand All @@ -4662,6 +4664,19 @@ function getSearchReportName(props: GetReportNameParams): string {
}
return getReportNameInternal(props);
}
function isChatThreadDeleted(report: OnyxInputOrEntry<Report>, reportActionParam: OnyxInputOrEntry<ReportAction>): boolean
{
if (!isChatThread(report)) {
return false
}

let reportAction = reportActionParam as OnyxEntry<ReportAction>
if (!reportAction) {
reportAction = getReportAction(report?.parentReportID, report?.parentReportActionID);
}

return isMessageDeleted(reportAction)
}

function getInvoiceReportName(report: OnyxEntry<Report>, policy?: OnyxEntry<Policy | SearchPolicy>, invoiceReceiverPolicy?: OnyxEntry<Policy | SearchPolicy>): string {
const moneyRequestReportName = getMoneyRequestReportName({report, policy, invoiceReceiverPolicy});
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -10948,6 +10963,7 @@ export {
isChatRoom,
isTripRoom,
isChatThread,
isChatThreadDeleted,
isChildReport,
isClosedExpenseReportWithNoExpenses,
isCompletedTaskReport,
Expand Down
119 changes: 119 additions & 0 deletions tests/unit/ReportActionsUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -734,6 +837,22 @@ describe('ReportActionsUtils', () => {
const expectedFragments = ReportActionsUtils.getReportActionMessageFragments(action);
expect(expectedFragments).toEqual([{text: expectedMessage, html: `<muted-text>${expectedMessage}</muted-text>`, 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', () => {
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down