diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index cf9fcf68a800..6d4997cfe06e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1910,7 +1910,7 @@ function getWorkspaceIcon(report: OnyxInputOrEntry, policy?: OnyxInputOr * Gets the personal details for a login by looking in the ONYXKEYS.PERSONAL_DETAILS_LIST Onyx key (stored in the local variable, allPersonalDetails). If it doesn't exist in Onyx, * then a default object is constructed. */ -function getPersonalDetailsForAccountID(accountID: number): Partial { +function getPersonalDetailsForAccountID(accountID: number, personalDetailsData?: Partial): Partial { if (!accountID) { return {}; } @@ -1919,7 +1919,11 @@ function getPersonalDetailsForAccountID(accountID: number): Partial = {}; /** * Get the displayName for a single report participant. */ -function getDisplayNameForParticipant(accountID?: number, shouldUseShortForm = false, shouldFallbackToHidden = true, shouldAddCurrentUserPostfix = false): string { +function getDisplayNameForParticipant( + accountID?: number, + shouldUseShortForm = false, + shouldFallbackToHidden = true, + shouldAddCurrentUserPostfix = false, + personalDetailsData?: Partial, +): string { if (!accountID) { return ''; } - const personalDetails = getPersonalDetailsOrDefault(allPersonalDetails?.[accountID]); + const personalDetails = getPersonalDetailsOrDefault(personalDetailsData?.[accountID] ?? allPersonalDetails?.[accountID]); if (!personalDetails) { return ''; } @@ -3482,7 +3492,12 @@ function getInvoicesChatName(report: OnyxEntry): string { /** * Get the title for a report. */ -function getReportName(report: OnyxEntry, policy?: OnyxEntry, parentReportActionParam?: OnyxInputOrEntry): string { +function getReportName( + report: OnyxEntry, + policy?: OnyxEntry, + parentReportActionParam?: OnyxInputOrEntry, + personalDetails?: Partial, +): string { let formattedName: string | undefined; const parentReportAction = parentReportActionParam ?? ReportActionsUtils.getParentReportAction(report); const parentReportActionMessage = ReportActionsUtils.getReportActionMessage(parentReportAction); @@ -3566,7 +3581,7 @@ function getReportName(report: OnyxEntry, policy?: OnyxEntry, pa } if (isSelfDM(report)) { - formattedName = getDisplayNameForParticipant(currentUserAccountID, undefined, undefined, true); + formattedName = getDisplayNameForParticipant(currentUserAccountID, undefined, undefined, true, personalDetails); } if (isInvoiceRoom(report)) { @@ -3586,7 +3601,7 @@ function getReportName(report: OnyxEntry, policy?: OnyxEntry, pa } }); const isMultipleParticipantReport = participantsWithoutCurrentUser.length > 1; - return participantsWithoutCurrentUser.map((accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport)).join(', '); + return participantsWithoutCurrentUser.map((accountID) => getDisplayNameForParticipant(accountID, isMultipleParticipantReport, true, false, personalDetails)).join(', '); } /** diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index cd372e0bd33b..626da27e22da 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -82,7 +82,7 @@ function HeaderView({report, personalDetails, parentReport, parentReportAction, const isTaskReport = ReportUtils.isTaskReport(report); const reportHeaderData = !isTaskReport && !isChatThread && report.parentReportID ? parentReport : report; // Use sorted display names for the title for group chats on native small screen widths - const title = ReportUtils.getReportName(reportHeaderData, undefined, parentReportAction); + const title = ReportUtils.getReportName(reportHeaderData, undefined, parentReportAction, personalDetails); const subtitle = ReportUtils.getChatRoomSubtitle(reportHeaderData); const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(reportHeaderData); const reportDescription = ReportUtils.getReportDescriptionText(report);