Skip to content
Merged
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
20 changes: 17 additions & 3 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ const regexMergedAccount = new RegExp(CONST.REGEX.MERGED_ACCOUNT_PREFIX);
function getDisplayNameOrDefault(passedPersonalDetails?: Partial<PersonalDetails> | null, defaultValue = '', shouldFallbackToHidden = true, shouldAddCurrentUserPostfix = false): 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.
Expand All @@ -60,8 +62,11 @@ function getDisplayNameOrDefault(passedPersonalDetails?: Partial<PersonalDetails

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

if (shouldAddCurrentUserPostfix && !!displayName) {
Expand All @@ -75,7 +80,16 @@ function getDisplayNameOrDefault(passedPersonalDetails?: Partial<PersonalDetails
if (displayName) {
return displayName;
}
return defaultValue || (shouldFallbackToHidden ? hiddenTranslation : '');

if (defaultValue) {
return defaultValue;
}

if (login) {
return login;
}

return shouldFallbackToHidden ? hiddenTranslation : '';
}

/**
Expand Down