Skip to content

Commit b183a43

Browse files
authored
Merge pull request Expensify#64161 from thelullabyy/fix/62991-LHN-not-show-message-sent
LHN-LHN doesn't show the message sent or the system message
2 parents 8391933 + 5236a8c commit b183a43

2 files changed

Lines changed: 75 additions & 2 deletions

File tree

src/libs/OptionsListUtils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,15 @@ function getLastMessageTextForReport(
869869
lastMessageTextFromReport = getReportActionMessageText(lastReportAction);
870870
}
871871

872+
if (reportID) {
873+
const chatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
874+
// If the report is a one-transaction report, get the last message text from combined report actions so the LHN can display modifications to the transaction thread or the report itself
875+
const transactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, allSortedReportActions[reportID]);
876+
if (transactionThreadReportID) {
877+
lastMessageTextFromReport = getReportActionMessageText(lastReportAction);
878+
}
879+
}
880+
872881
return lastMessageTextFromReport || (report?.lastMessageText ?? '');
873882
}
874883

tests/unit/SidebarUtilsTest.ts

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
44
import Onyx from 'react-native-onyx';
55
import useReportIsArchived from '@hooks/useReportIsArchived';
66
import DateUtils from '@libs/DateUtils';
7-
import {getReportActionMessageText} from '@libs/ReportActionsUtils';
7+
import {getOriginalMessage, getReportActionMessageText} from '@libs/ReportActionsUtils';
88
import {getAllReportErrors} from '@libs/ReportUtils';
99
import SidebarUtils from '@libs/SidebarUtils';
1010
import initOnyxDerivedValues from '@userActions/OnyxDerived';
@@ -14,7 +14,8 @@ import ONYXKEYS from '@src/ONYXKEYS';
1414
import type {Policy, Report, ReportAction, ReportActions, Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx';
1515
import type {ReportCollectionDataSet} from '@src/types/onyx/Report';
1616
import type {TransactionViolationsCollectionDataSet} from '@src/types/onyx/TransactionViolation';
17-
import {chatReportR14932} from '../../__mocks__/reportData/reports';
17+
import {actionR14932 as mockIOUAction} from '../../__mocks__/reportData/actions';
18+
import {chatReportR14932, iouReportR14932} from '../../__mocks__/reportData/reports';
1819
import createRandomPolicy from '../utils/collections/policies';
1920
import createRandomReportAction from '../utils/collections/reportActions';
2021
import createRandomReport from '../utils/collections/reports';
@@ -1126,6 +1127,69 @@ describe('SidebarUtils', () => {
11261127
oneTransactionThreadReport: undefined,
11271128
});
11281129

1130+
expect(result?.alternateText).toBe(`You: ${getReportActionMessageText(lastAction)}`);
1131+
});
1132+
it('returns the last action message as an alternate text if the expense report is the one expense report', async () => {
1133+
const IOUTransactionID = `${ONYXKEYS.COLLECTION.TRANSACTION}TRANSACTION_IOU` as const;
1134+
1135+
iouReportR14932.reportID = '5';
1136+
chatReportR14932.reportID = '6';
1137+
iouReportR14932.lastActorAccountID = undefined;
1138+
1139+
const report: Report = {
1140+
...createRandomReport(1),
1141+
chatType: 'policyExpenseChat',
1142+
pendingAction: null,
1143+
isOwnPolicyExpenseChat: true,
1144+
parentReportID: iouReportR14932.reportID,
1145+
parentReportActionID: mockIOUAction.reportActionID,
1146+
lastActorAccountID: undefined,
1147+
};
1148+
1149+
const linkedCreateAction: ReportAction = {
1150+
...mockIOUAction,
1151+
originalMessage: {...getOriginalMessage(mockIOUAction), IOUTransactionID},
1152+
childReportID: report.reportID,
1153+
reportActionID: '3',
1154+
};
1155+
1156+
const lastAction: ReportAction = {
1157+
...createRandomReportAction(1),
1158+
message: [
1159+
{
1160+
type: 'COMMENT',
1161+
html: 'test action',
1162+
text: 'test action',
1163+
},
1164+
],
1165+
originalMessage: {
1166+
whisperedTo: [],
1167+
},
1168+
1169+
created: DateUtils.getDBTime(),
1170+
lastModified: DateUtils.getDBTime(),
1171+
shouldShow: true,
1172+
pendingAction: null,
1173+
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
1174+
actorAccountID: undefined,
1175+
};
1176+
1177+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${iouReportR14932.reportID}`, iouReportR14932);
1178+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${chatReportR14932.reportID}`, chatReportR14932);
1179+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
1180+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {[lastAction.reportActionID]: lastAction});
1181+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportR14932.reportID}`, {[linkedCreateAction.reportActionID]: linkedCreateAction});
1182+
1183+
const result = SidebarUtils.getOptionData({
1184+
report: iouReportR14932,
1185+
reportAttributes: undefined,
1186+
reportNameValuePairs: {},
1187+
personalDetails: {},
1188+
policy: undefined,
1189+
parentReportAction: undefined,
1190+
oneTransactionThreadReport: undefined,
1191+
});
1192+
11291193
expect(result?.alternateText).toBe(`You: ${getReportActionMessageText(lastAction)}`);
11301194
});
11311195
});

0 commit comments

Comments
 (0)