Skip to content

Commit 877f867

Browse files
authored
Merge pull request #38957 from ahmedGaber93/fix-38079
update MentionUserRenderer.tsx display text
2 parents 5facc1c + fe4736e commit 877f867

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona
3535
const htmlAttributeAccountID = tnode.attributes.accountid;
3636

3737
let accountID: number;
38-
let displayNameOrLogin: string;
38+
let mentionDisplayText: string;
3939
let navigationRoute: Route;
4040

4141
const tnodeClone = cloneDeep(tnode);
4242

43-
const getMentionDisplayText = (displayText: string, userAccountID: string, userLogin = '') => {
43+
const getShortMentionIfFound = (displayText: string, userAccountID: string, userLogin = '') => {
4444
// If the userAccountID does not exist, this is an email-based mention so the displayText must be an email.
4545
// If the userAccountID exists but userLogin is different from displayText, this means the displayText is either user display name, Hidden, or phone number, in which case we should return it as is.
4646
if (userAccountID && userLogin !== displayText) {
@@ -59,18 +59,18 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona
5959
if (!isEmpty(htmlAttribAccountID)) {
6060
const user = personalDetails[htmlAttribAccountID];
6161
accountID = parseInt(htmlAttribAccountID, 10);
62-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
63-
displayNameOrLogin = PersonalDetailsUtils.getDisplayNameOrDefault(user, LocalePhoneNumber.formatPhoneNumber(user?.login ?? ''));
62+
mentionDisplayText = LocalePhoneNumber.formatPhoneNumber(user?.login ?? '') || PersonalDetailsUtils.getDisplayNameOrDefault(user);
63+
mentionDisplayText = getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID, user?.login ?? '');
6464
navigationRoute = ROUTES.PROFILE.getRoute(htmlAttribAccountID);
6565
} else if ('data' in tnodeClone && !isEmptyObject(tnodeClone.data)) {
6666
// We need to remove the LTR unicode and leading @ from data as it is not part of the login
67-
displayNameOrLogin = tnodeClone.data.replace(CONST.UNICODE.LTR, '').slice(1);
67+
mentionDisplayText = tnodeClone.data.replace(CONST.UNICODE.LTR, '').slice(1);
6868
// We need to replace tnode.data here because we will pass it to TNodeChildrenRenderer below
69-
asMutable(tnodeClone).data = tnodeClone.data.replace(displayNameOrLogin, Str.removeSMSDomain(getMentionDisplayText(displayNameOrLogin, htmlAttributeAccountID)));
69+
asMutable(tnodeClone).data = tnodeClone.data.replace(mentionDisplayText, Str.removeSMSDomain(getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID)));
7070

71-
accountID = PersonalDetailsUtils.getAccountIDsByLogins([displayNameOrLogin])?.[0];
72-
navigationRoute = ROUTES.DETAILS.getRoute(displayNameOrLogin);
73-
displayNameOrLogin = Str.removeSMSDomain(displayNameOrLogin);
71+
accountID = PersonalDetailsUtils.getAccountIDsByLogins([mentionDisplayText])?.[0];
72+
navigationRoute = ROUTES.DETAILS.getRoute(mentionDisplayText);
73+
mentionDisplayText = Str.removeSMSDomain(mentionDisplayText);
7474
} else {
7575
// If neither an account ID or email is provided, don't render anything
7676
return null;
@@ -97,7 +97,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona
9797
<UserDetailsTooltip
9898
accountID={accountID}
9999
fallbackUserDetails={{
100-
displayName: displayNameOrLogin,
100+
displayName: mentionDisplayText,
101101
}}
102102
>
103103
<Text
@@ -108,7 +108,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona
108108
testID="span"
109109
href={`/${navigationRoute}`}
110110
>
111-
{htmlAttribAccountID ? `@${displayNameOrLogin}` : <TNodeChildrenRenderer tnode={tnodeClone} />}
111+
{htmlAttribAccountID ? `@${mentionDisplayText}` : <TNodeChildrenRenderer tnode={tnodeClone} />}
112112
</Text>
113113
</UserDetailsTooltip>
114114
</Text>

0 commit comments

Comments
 (0)