Skip to content
Open
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
1 change: 1 addition & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2925,6 +2925,7 @@ const CONST = {
},

CONCIERGE_DISPLAY_NAME: 'Concierge',
HIDDEN_DISPLAY_NAME: 'Hidden',
CONCIERGE_GREETING_ACTION_ID: 'concierge-greeting',

INTEGRATION_ENTITY_MAP_TYPES: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function useReportActionAvatars({
const accountID = reportPreviewSenderID || (actorAccountID ?? CONST.DEFAULT_NUMBER_ID);
const {avatar, fallbackIcon, login} = personalDetails?.[delegatePersonalDetails ? delegatePersonalDetails.accountID : accountID] ?? {};

const defaultDisplayName = getDisplayNameForParticipant({accountID, personalDetailsData: personalDetails, formatPhoneNumber, translate}) ?? '';
const defaultDisplayName = getDisplayNameForParticipant({accountID, personalDetailsData: personalDetails, formatPhoneNumber, hiddenTranslation: translate('common.hidden')}) ?? '';
const invoiceReport = [iouReport, chatReport, reportChatReport].find((susReport) => isInvoiceReport(susReport) || susReport?.chatType === CONST.REPORT.TYPE.INVOICE);
const isNestedInInvoiceReport = !!invoiceReport && !isChatThread(report);
const isInvoiceReportActor = isAInvoiceReport && (!actorAccountID || displayAllActors || isAReportPreviewAction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function usePreviewMessageAnimation({
accountID: managerID,
shouldUseShortForm: true,
formatPhoneNumber,
translate,
hiddenTranslation: translate('common.hidden'),
});
}

Expand All @@ -144,7 +144,7 @@ function usePreviewMessageAnimation({
accountID: chatReport?.ownerAccountID,
shouldUseShortForm: true,
formatPhoneNumber,
translate,
hiddenTranslation: translate('common.hidden'),
});
}
return translate(paymentVerb, payerOrApproverName);
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/TaskView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function TaskView({report, parentReport, action}: TaskViewProps) {
{report?.managerID ? (
<MenuItem
label={translate('task.assignee')}
title={getDisplayNameForParticipant({accountID: report.managerID, formatPhoneNumber, translate})}
title={getDisplayNameForParticipant({accountID: report.managerID, formatPhoneNumber, hiddenTranslation: translate('common.hidden')})}
iconAccountID={report.managerID}
iconType={CONST.ICON_TYPE_AVATAR}
avatarSize={CONST.AVATAR_SIZE.X_SMALL}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function UserSelectionListItem<TItem extends ListItem>({
return getDisplayNameForParticipant({
accountID: item.accountID ?? CONST.DEFAULT_NUMBER_ID,
formatPhoneNumber,
translate,
hiddenTranslation: translate('common.hidden'),
});
}, [formatPhoneNumber, item.accountID, translate]);

Expand Down
2 changes: 1 addition & 1 deletion src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function buildNextStepMessage(
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
): string {
// Escape actor name to prevent HTML injection since this will be rendered as HTML
const actor = Str.safeEscape(getDisplayNameForParticipant({accountID: nextStep.actorAccountID, formatPhoneNumber, translate}) ?? '');
const actor = Str.safeEscape(getDisplayNameForParticipant({accountID: nextStep.actorAccountID, formatPhoneNumber, hiddenTranslation: translate('common.hidden')}) ?? '');
let actorType: ValueOf<typeof CONST.NEXT_STEP.ACTOR_TYPE>;
if (nextStep.actorAccountID === currentUserAccountID) {
actorType = CONST.NEXT_STEP.ACTOR_TYPE.CURRENT_USER;
Expand Down
11 changes: 8 additions & 3 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,10 @@ function createOption({
let reportName;
result.participantsList = personalDetailList;

// Resolve display-name translations once per option, then pass the strings to getDisplayNameForParticipant.
const hiddenText = translateFn('common.hidden');
const youText = translateFn('common.you').toLowerCase();

if (report) {
result.private_isArchived = privateIsArchived;
result.keyForList = String(report.reportID);
Expand Down Expand Up @@ -1271,12 +1275,13 @@ function createOption({
shouldAddCurrentUserPostfix: true,
personalDetailsData: personalDetails ?? undefined,
formatPhoneNumber: formatPhoneNumberPhoneUtils,
translate: translateFn,
hiddenTranslation: hiddenText,
youTranslation: youText,
})
: '');

reportName = showPersonalDetails
? getDisplayNameForParticipant({accountID: accountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils, translate: translateFn}) ||
? getDisplayNameForParticipant({accountID: accountIDs.at(0), formatPhoneNumber: formatPhoneNumberPhoneUtils, hiddenTranslation: hiddenText}) ||
formatPhoneNumberPhoneUtils(personalDetail?.login ?? '')
: computedReportName;
} else {
Expand All @@ -1285,7 +1290,7 @@ function createOption({
accountID: accountIDs.at(0),
personalDetailsData: personalDetails ?? undefined,
formatPhoneNumber: formatPhoneNumberPhoneUtils,
translate: translateFn,
hiddenTranslation: hiddenText,
}) || formatPhoneNumberPhoneUtils(personalDetail?.login ?? '');
result.keyForList = String(accountIDs.at(0));

Expand Down
2 changes: 1 addition & 1 deletion src/libs/PersonalDetailOptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function createOption(
accountID: personalDetail.accountID,
formatPhoneNumber,
personalDetailsData: {[personalDetail.accountID]: personalDetail},
translate,
hiddenTranslation: translate?.('common.hidden'),
}) || formatPhoneNumber(personalDetail.login ?? '');
result.icons = [
{
Expand Down
72 changes: 5 additions & 67 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {Str} from 'expensify-common';
import Onyx from 'react-native-onyx';

import {getCountryCode} from './CountryUtils';
import {translateLocal} from './Localize';
import {areEmailsFromSamePrivateDomain} from './LoginUtils';
import {addSMSDomainIfPhoneNumber, parsePhoneNumber} from './PhoneNumber';
import {getDefaultAvatarURL} from './UserAvatarUtils';
Expand Down Expand Up @@ -44,76 +43,15 @@ Onyx.connect({
},
});

let hiddenTranslation = '';
let youTranslation = '';

Onyx.connect({
key: ONYXKEYS.RAM_ONLY_ARE_TRANSLATIONS_LOADING,
callback: (value) => {
if (value ?? true) {
return;
}
hiddenTranslation = translateLocal('common.hidden');
youTranslation = translateLocal('common.you').toLowerCase();
},
});

const regexMergedAccount = new RegExp(CONST.REGEX.MERGED_ACCOUNT_PREFIX);

function getDisplayNameOrDefault(
passedPersonalDetails?: Partial<PersonalDetails> | null,
defaultValue = '',
shouldFallbackToHidden = true,
shouldAddCurrentUserPostfix = false,
youAfterTranslation = youTranslation,
): string {
let displayName = passedPersonalDetails?.displayName ?? '';

let login = passedPersonalDetails?.login ?? '';

// If the displayName starts with the merged account prefix, remove it.
if (regexMergedAccount.test(displayName)) {
// Remove the merged account prefix from the displayName.
displayName = displayName.replaceAll(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
}

// If the displayName is not set by the user, the backend sets the displayName same as the login so
// we need to remove the sms domain from the displayName if it is an sms login.
if (Str.isSMSLogin(login)) {
if (displayName === login) {
displayName = Str.removeSMSDomain(displayName);
}
login = Str.removeSMSDomain(login);
}

if (shouldAddCurrentUserPostfix && !!displayName) {
displayName = `${displayName} (${youAfterTranslation})`;
}

if (passedPersonalDetails?.accountID === CONST.ACCOUNT_ID.CONCIERGE) {
displayName = CONST.CONCIERGE_DISPLAY_NAME;
}

if (displayName) {
return displayName;
}

if (defaultValue) {
return defaultValue;
}

if (login) {
return login;
}
return shouldFallbackToHidden ? hiddenTranslation : '';
}

function temporaryGetDisplayNameOrDefault({
passedPersonalDetails,
defaultValue = '',
shouldFallbackToHidden = true,
shouldAddCurrentUserPostfix = false,
youAfterTranslation,
hiddenAfterTranslation,
translate,
formatPhoneNumber,
}: {
Expand All @@ -122,11 +60,12 @@ function temporaryGetDisplayNameOrDefault({
shouldFallbackToHidden?: boolean;
shouldAddCurrentUserPostfix?: boolean;
youAfterTranslation?: string;
translate: LocalizedTranslate;
hiddenAfterTranslation?: string;
translate?: LocalizedTranslate;
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'];
}): string {
const temporaryHiddenTranslation = translate('common.hidden');
const temporaryYouTranslation = translate('common.you').toLowerCase();
const temporaryHiddenTranslation = hiddenAfterTranslation ?? translate?.('common.hidden') ?? '';
const temporaryYouTranslation = translate?.('common.you').toLowerCase();
let displayName = passedPersonalDetails?.displayName ?? '';

const login = passedPersonalDetails?.login ?? '';
Expand Down Expand Up @@ -577,7 +516,6 @@ function areTravelPersonalDetailsMissing(privatePersonalDetails: OnyxEntry<Priva
}

export {
getDisplayNameOrDefault,
getPersonalDetailsByID,
getPersonalDetailsByIDs,
getParticipantsPersonalDetails,
Expand Down
23 changes: 15 additions & 8 deletions src/libs/ReportNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const buildReportNameFromParticipantNames = ({
shouldUseShortForm: true,
personalDetailsData,
formatPhoneNumber: formatPhoneNumberPhoneUtils,
translate,
hiddenTranslation: translate('common.hidden'),
}),
}))
.filter((participant) => participant.name)
Expand All @@ -247,7 +247,7 @@ const buildReportNameFromParticipantNames = ({
accountID,
personalDetailsData,
formatPhoneNumber: formatPhoneNumberPhoneUtils,
translate,
hiddenTranslation: translate('common.hidden'),
});
}
return formattedNames ? `${formattedNames}, ${name}` : name;
Expand Down Expand Up @@ -293,10 +293,12 @@ function getGroupChatName(
const isMultipleParticipantReport = participantAccountIDs.length > 1;

if (isMultipleParticipantReport) {
// Resolve the translation once, not per participant.
const hiddenText = translate('common.hidden');
return participantAccountIDs
.map(
(participantAccountID, index) =>
getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber, translate}) ||
getDisplayNameForParticipant({accountID: participantAccountID, shouldUseShortForm: isMultipleParticipantReport, formatPhoneNumber, hiddenTranslation: hiddenText}) ||
formatPhoneNumber(participants?.[index]?.login ?? ''),
)
.sort((first, second) => customCollator.compare(first ?? '', second ?? ''))
Expand All @@ -305,7 +307,7 @@ function getGroupChatName(
.slice(0, CONST.REPORT_NAME_LIMIT)
.concat(shouldAddEllipsis ? '...' : '');
}
return translate('groupChat.defaultReportName', getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber, translate}));
return translate('groupChat.defaultReportName', getDisplayNameForParticipant({accountID: participantAccountIDs.at(0), formatPhoneNumber, hiddenTranslation: translate('common.hidden')}));
}

/**
Expand All @@ -324,7 +326,9 @@ function getPolicyExpenseChatName({
const personalDetails = ownerAccountID ? personalDetailsList?.[ownerAccountID] : undefined;
const login = personalDetails ? personalDetails.login : null;

const reportOwnerDisplayName = getDisplayNameForParticipant({accountID: ownerAccountID, shouldRemoveDomain: true, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) || login;
const reportOwnerDisplayName =
getDisplayNameForParticipant({accountID: ownerAccountID, shouldRemoveDomain: true, formatPhoneNumber: formatPhoneNumberPhoneUtils, hiddenTranslation: translate('common.hidden')}) ||
login;

if (reportOwnerDisplayName) {
return translate('workspace.common.policyExpenseChatName', reportOwnerDisplayName);
Expand Down Expand Up @@ -453,7 +457,8 @@ function getMoneyRequestReportName({
const invoiceReceiverPersonalDetail = getInvoiceReceiverPersonalDetail(chatReport, personalDetailsList);
payerOrApproverName = getInvoicePayerName(chatReport, translate, invoiceReceiverPersonalDetail, invoiceReceiverPolicy);
} else {
payerOrApproverName = getDisplayNameForParticipant({accountID: report?.managerID, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) ?? '';
payerOrApproverName =
getDisplayNameForParticipant({accountID: report?.managerID, formatPhoneNumber: formatPhoneNumberPhoneUtils, hiddenTranslation: translate('common.hidden')}) ?? '';
}
const payerPaidAmountMessage = translate('iou.payerPaidAmount', formattedAmount, payerOrApproverName);

Expand All @@ -466,7 +471,8 @@ function getMoneyRequestReportName({
}

if (!isSettled(report?.reportID) && hasNonReimbursableTransactions(linkedTransactions)) {
payerOrApproverName = getDisplayNameForParticipant({accountID: report?.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils, translate}) ?? '';
payerOrApproverName =
getDisplayNameForParticipant({accountID: report?.ownerAccountID, formatPhoneNumber: formatPhoneNumberPhoneUtils, hiddenTranslation: translate('common.hidden')}) ?? '';
return translate('iou.payerSpentAmount', formattedAmount, payerOrApproverName);
}

Expand Down Expand Up @@ -1185,7 +1191,8 @@ function computeReportName({
shouldAddCurrentUserPostfix: true,
personalDetailsData: personalDetailsList,
formatPhoneNumber: formatPhoneNumberPhoneUtils,
translate,
hiddenTranslation: translate('common.hidden'),
youTranslation: translate('common.you').toLowerCase(),
});
}

Expand Down
Loading
Loading