Skip to content

Commit bee2cb5

Browse files
authored
Merge pull request #59326 from daledah/fix/58938
fix: remove last actor on archived message
2 parents 8cf3e2c + 0e6ee6b commit bee2cb5

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

src/libs/OptionsListUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ function createOption(
895895
lastAction &&
896896
lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW &&
897897
lastAction.actionName !== CONST.REPORT.ACTIONS.TYPE.IOU &&
898+
!isArchivedNonExpenseReport(report, reportNameValuePairs) &&
898899
shouldShowLastActorDisplayName(report, lastActorDetails);
899900
if (shouldDisplayLastActorName && lastActorDisplayName && lastMessageTextFromReport) {
900901
lastMessageText = `${lastActorDisplayName}: ${lastMessageTextFromReport}`;

src/libs/SidebarUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import {
8686
isAdminRoom,
8787
isAnnounceRoom,
8888
isArchivedNonExpenseReport,
89+
isArchivedReport,
8990
isArchivedReportWithID,
9091
isChatRoom,
9192
isChatThread,
@@ -666,8 +667,7 @@ function getOptionData({
666667
if (!lastMessageText) {
667668
lastMessageText = formatReportLastMessageText(getWelcomeMessage(report, policy).messageText ?? translateLocal('report.noActivityYet'));
668669
}
669-
670-
if (shouldShowLastActorDisplayName(report, lastActorDetails)) {
670+
if (shouldShowLastActorDisplayName(report, lastActorDetails) && !isArchivedReport(reportNameValuePairs)) {
671671
result.alternateText = `${lastActorDisplayName}: ${formatReportLastMessageText(Parser.htmlToText(lastMessageText)) || formattedLogin}`;
672672
} else {
673673
result.alternateText = formatReportLastMessageText(Parser.htmlToText(lastMessageText)) || formattedLogin;

tests/unit/OptionsListUtilsTest.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,21 @@ import {
2525
import type {OptionList, Options, SearchOption} from '@src/libs/OptionsListUtils';
2626
import ONYXKEYS from '@src/ONYXKEYS';
2727
import type {PersonalDetails, Policy, Report} from '@src/types/onyx';
28+
import {getFakeAdvancedReportAction} from '../utils/LHNTestUtils';
2829
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
2930

31+
jest.mock('@rnmapbox/maps', () => {
32+
return {
33+
default: jest.fn(),
34+
MarkerView: jest.fn(),
35+
setAccessToken: jest.fn(),
36+
};
37+
});
38+
39+
jest.mock('@react-native-community/geolocation', () => ({
40+
setRNConfiguration: jest.fn(),
41+
}));
42+
3043
type PersonalDetailsList = Record<string, PersonalDetails & OptionData>;
3144

3245
describe('OptionsListUtils', () => {
@@ -179,6 +192,7 @@ describe('OptionsListUtils', () => {
179192
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
180193
isOwnPolicyExpenseChat: true,
181194
type: CONST.REPORT.TYPE.CHAT,
195+
lastActorAccountID: 2,
182196
},
183197
'11': {
184198
lastReadTime: '2021-01-14 11:25:39.200',
@@ -1357,6 +1371,20 @@ describe('OptionsListUtils', () => {
13571371
});
13581372
});
13591373

1374+
describe('Alternative text', () => {
1375+
it("The text should not contain the last actor's name at prefix if the report is archived.", async () => {
1376+
await Onyx.multiSet({
1377+
[ONYXKEYS.NVP_PREFERRED_LOCALE]: CONST.LOCALES.EN,
1378+
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}10` as const]: {
1379+
'1': getFakeAdvancedReportAction(CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT),
1380+
},
1381+
});
1382+
const reports = createOptionList(PERSONAL_DETAILS, REPORTS).reports;
1383+
const archivedReport = reports.find((report) => report.reportID === '10');
1384+
expect(archivedReport?.lastMessageText).toBe('This chat room has been archived.'); // Default archived reason
1385+
});
1386+
});
1387+
13601388
describe('filterSelfDMChat', () => {
13611389
const REPORT = {
13621390
reportID: '1',

tests/unit/SidebarUtilsTest.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,42 @@ describe('SidebarUtils', () => {
617617

618618
expect(optionData?.alternateText).toBe(`test message`);
619619
});
620+
it("The text should not contain the last actor's name at prefix if the report is archived.", async () => {
621+
const preferredLocale = 'en';
622+
const policy: Policy = {
623+
...createRandomPolicy(1),
624+
role: CONST.POLICY.ROLE.ADMIN,
625+
pendingAction: null,
626+
};
627+
const report: Report = {
628+
...createRandomReport(2),
629+
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
630+
policyID: policy.id,
631+
policyName: policy.name,
632+
type: CONST.REPORT.TYPE.CHAT,
633+
lastActorAccountID: 1,
634+
};
635+
const reportNameValuePairs = {
636+
private_isArchived: DateUtils.getDBTime(),
637+
};
638+
639+
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}1`, policy);
640+
641+
const optionData = SidebarUtils.getOptionData({
642+
report,
643+
reportNameValuePairs,
644+
reportActions: {},
645+
personalDetails: LHNTestUtils.fakePersonalDetails,
646+
preferredLocale,
647+
policy,
648+
parentReportAction: undefined,
649+
hasViolations: false,
650+
lastMessageTextFromReport: 'test message',
651+
oneTransactionThreadReport: undefined,
652+
});
653+
654+
expect(optionData?.alternateText).toBe(`test message`);
655+
});
620656
it('The text should not contain the policy name at prefix if we only have a workspace', async () => {
621657
const preferredLocale = 'en';
622658
const policy: Policy = {

0 commit comments

Comments
 (0)