Skip to content

Fix - Display @Hidden mentions in LHN #59551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 1, 2025
15 changes: 14 additions & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,19 @@ import Navigation from './Navigation/Navigation';
import Parser from './Parser';
import Performance from './Performance';
import Permissions from './Permissions';
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
import {getDisplayNameOrDefault, getPersonalDetailsByIDs} from './PersonalDetailsUtils';
import {addSMSDomainIfPhoneNumber, parsePhoneNumber} from './PhoneNumber';
import {canSendInvoiceFromWorkspace, getSubmitToAccountID, isUserInvitedToWorkspace} from './PolicyUtils';
import {
getCombinedReportActions,
getExportIntegrationLastMessageText,
getIOUReportIDFromReportActionPreview,
getLeaveRoomMessage,
getMentionedAccountIDsFromAction,
getMessageOfOldDotReportAction,
getOneTransactionThreadReportID,
getOriginalMessage,
getReportActionHtml,
getReportActionMessageText,
getSortedReportActions,
getUpdateRoomDescriptionMessage,
Expand Down Expand Up @@ -682,6 +684,10 @@ function getIOUReportIDOfLastAction(report: OnyxEntry<Report>): string | undefin
return getReportOrDraftReport(getIOUReportIDFromReportActionPreview(lastAction))?.reportID;
}

function hasHiddenDisplayNames(accountIDs: number[]) {
return getPersonalDetailsByIDs({accountIDs, currentUserAccountID: 0}).some((personalDetail) => !getDisplayNameOrDefault(personalDetail, undefined, false));
}

/**
* Get the last message text from the report directly or from other sources for special cases.
*/
Expand Down Expand Up @@ -807,6 +813,13 @@ function getLastMessageTextForReport(
if (reportID && !isArchivedReport(reportNameValuePairs) && report.lastActionType === CONST.REPORT.ACTIONS.TYPE.CLOSED) {
return lastMessageTextFromReport || (getReportLastMessage(reportID).lastMessageText ?? '');
}

// When the last report action has unkown mentions (@Hidden), we want to consistently show @Hidden in LHN and report screen
// so we reconstruct the last message text of the report from the last report action.
if (!lastMessageTextFromReport && lastReportAction && hasHiddenDisplayNames(getMentionedAccountIDsFromAction(lastReportAction))) {
lastMessageTextFromReport = Parser.htmlToText(getReportActionHtml(lastReportAction));
}

return lastMessageTextFromReport || (report?.lastMessageText ?? '');
}

Expand Down
1 change: 1 addition & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2447,6 +2447,7 @@ export {
isReportActionDeprecated,
isReportPreviewAction,
isReversedTransaction,
getMentionedAccountIDsFromAction,
isRoomChangeLogAction,
isSentMoneyReportAction,
isSplitBillAction,
Expand Down
60 changes: 60 additions & 0 deletions tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,66 @@ describe('SidebarUtils', () => {
// Then the alternate text should be equal to the message of the last action prepended with the last actor display name.
expect(result?.alternateText).toBe(`${lastAction.person?.[0].text}: ${getReportActionMessageText(lastAction)}`);
});

it('returns @Hidden as an alternate text if the last action mentioned account has no name', async () => {
// When a report has last action with mention of an account that has no name
const report: Report = {
...createRandomReport(4),
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
lastMessageText: '@[email protected]',
lastVisibleActionCreated: '2025-01-20 12:30:03.784',
};

const mentionedAccountID = 19797552;
const lastAction: ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT> = {
...createRandomReportAction(2),
message: [
{
html: `<mention-user accountID="${mentionedAccountID}"/>`,
text: '@[email protected]',
type: 'COMMENT',
whisperedTo: [],
},
],
originalMessage: {
html: `<mention-user accountID="${mentionedAccountID}"/>`,
whisperedTo: [],
lastModified: '2025-05-01 13:23:25.209',
mentionedAccountIDs: [mentionedAccountID],
},
previousMessage: undefined,
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
actorAccountID: 119086,
person: [
{
type: 'TEXT',
style: 'strong',
text: 'f50',
},
],
};
const reportActions: ReportActions = {[lastAction.reportActionID]: lastAction};
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
await Onyx.set(ONYXKEYS.PERSONAL_DETAILS_LIST, {[mentionedAccountID]: {accountID: mentionedAccountID, firstName: '', lastName: ''}});
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, reportActions);

const result = SidebarUtils.getOptionData({
report,
reportActions,
reportAttributes: {},
reportNameValuePairs: {},
hasViolations: false,
personalDetails: {},
policy: undefined,
parentReportAction: undefined,
preferredLocale: CONST.LOCALES.EN,
oneTransactionThreadReport: undefined,
});

// Then the alternate text should show @Hidden.
expect(result?.alternateText).toBe(`f50: @Hidden`);
});

describe('Alternative text', () => {
afterEach(async () => {
Onyx.clear();
Expand Down