From fe4736ef3b2c9ca4a47f1a47680940d9886ac305 Mon Sep 17 00:00:00 2001 From: gaber Date: Thu, 28 Mar 2024 21:46:25 +0200 Subject: [PATCH] clean MentionUserRenderer.tsx mentionDisplayText --- .../HTMLRenderers/MentionUserRenderer.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx index d3376a798a8b..0c7c82534bbb 100644 --- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx +++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx @@ -35,12 +35,12 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona const htmlAttributeAccountID = tnode.attributes.accountid; let accountID: number; - let displayNameOrLogin: string; + let mentionDisplayText: string; let navigationRoute: Route; const tnodeClone = cloneDeep(tnode); - const getMentionDisplayText = (displayText: string, userAccountID: string, userLogin = '') => { + const getShortMentionIfFound = (displayText: string, userAccountID: string, userLogin = '') => { // If the userAccountID does not exist, this is an email-based mention so the displayText must be an email. // 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. if (userAccountID && userLogin !== displayText) { @@ -59,18 +59,18 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona if (!isEmpty(htmlAttribAccountID)) { const user = personalDetails[htmlAttribAccountID]; accountID = parseInt(htmlAttribAccountID, 10); - displayNameOrLogin = LocalePhoneNumber.formatPhoneNumber(user?.login ?? '') || PersonalDetailsUtils.getDisplayNameOrDefault(user); - displayNameOrLogin = Str.removeSMSDomain(getMentionDisplayText(displayNameOrLogin, htmlAttributeAccountID, user?.login ?? '')); + mentionDisplayText = LocalePhoneNumber.formatPhoneNumber(user?.login ?? '') || PersonalDetailsUtils.getDisplayNameOrDefault(user); + mentionDisplayText = getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID, user?.login ?? ''); navigationRoute = ROUTES.PROFILE.getRoute(htmlAttribAccountID); } else if ('data' in tnodeClone && !isEmptyObject(tnodeClone.data)) { // We need to remove the LTR unicode and leading @ from data as it is not part of the login - displayNameOrLogin = tnodeClone.data.replace(CONST.UNICODE.LTR, '').slice(1); + mentionDisplayText = tnodeClone.data.replace(CONST.UNICODE.LTR, '').slice(1); // We need to replace tnode.data here because we will pass it to TNodeChildrenRenderer below - asMutable(tnodeClone).data = tnodeClone.data.replace(displayNameOrLogin, Str.removeSMSDomain(getMentionDisplayText(displayNameOrLogin, htmlAttributeAccountID))); + asMutable(tnodeClone).data = tnodeClone.data.replace(mentionDisplayText, Str.removeSMSDomain(getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID))); - accountID = PersonalDetailsUtils.getAccountIDsByLogins([displayNameOrLogin])?.[0]; - navigationRoute = ROUTES.DETAILS.getRoute(displayNameOrLogin); - displayNameOrLogin = Str.removeSMSDomain(displayNameOrLogin); + accountID = PersonalDetailsUtils.getAccountIDsByLogins([mentionDisplayText])?.[0]; + navigationRoute = ROUTES.DETAILS.getRoute(mentionDisplayText); + mentionDisplayText = Str.removeSMSDomain(mentionDisplayText); } else { // If neither an account ID or email is provided, don't render anything return null; @@ -97,7 +97,7 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona - {htmlAttribAccountID ? `@${displayNameOrLogin}` : } + {htmlAttribAccountID ? `@${mentionDisplayText}` : }