diff --git a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx
index 9b202d3b4308..5c9d432ff321 100644
--- a/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx
+++ b/src/components/HTMLEngineProvider/HTMLRenderers/MentionUserRenderer.tsx
@@ -15,9 +15,8 @@ import type {WithCurrentUserPersonalDetailsProps} from '@components/withCurrentU
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
-import {areEmailsFromSamePrivateDomain} from '@libs/LoginUtils';
import Navigation from '@libs/Navigation/Navigation';
-import {getAccountIDsByLogins, getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils';
+import {getAccountIDsByLogins, getDisplayNameOrDefault, getShortMentionIfFound} from '@libs/PersonalDetailsUtils';
import {isArchivedNonExpenseReport} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
@@ -41,33 +40,20 @@ function MentionUserRenderer({style, tnode, TDefaultRenderer, currentUserPersona
const tnodeClone = cloneDeep(tnode);
- 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) {
- return displayText;
- }
-
- // If the emails are not in the same private domain, we also return the displayText
- if (!areEmailsFromSamePrivateDomain(displayText, currentUserPersonalDetails.login ?? '')) {
- return displayText;
- }
-
- // Otherwise, the emails must be of the same private domain, so we should remove the domain part
- return displayText.split('@').at(0);
- };
-
if (!isEmpty(htmlAttribAccountID) && personalDetails?.[htmlAttribAccountID]) {
const user = personalDetails[htmlAttribAccountID];
accountID = parseInt(htmlAttribAccountID, 10);
mentionDisplayText = formatPhoneNumber(user?.login ?? '') || getDisplayNameOrDefault(user);
- mentionDisplayText = getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID, user?.login ?? '') ?? '';
+ mentionDisplayText = getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID, currentUserPersonalDetails, user?.login ?? '') ?? '';
navigationRoute = ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute());
} 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
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(mentionDisplayText, Str.removeSMSDomain(getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID) ?? ''));
+ asMutable(tnodeClone).data = tnodeClone.data.replace(
+ mentionDisplayText,
+ Str.removeSMSDomain(getShortMentionIfFound(mentionDisplayText, htmlAttributeAccountID, currentUserPersonalDetails) ?? ''),
+ );
accountID = getAccountIDsByLogins([mentionDisplayText])?.at(0) ?? -1;
navigationRoute = ROUTES.PROFILE.getRoute(accountID, Navigation.getReportRHPActiveRoute(), mentionDisplayText);
diff --git a/src/libs/PersonalDetailsUtils.ts b/src/libs/PersonalDetailsUtils.ts
index 304181158f4e..e867055bbb58 100644
--- a/src/libs/PersonalDetailsUtils.ts
+++ b/src/libs/PersonalDetailsUtils.ts
@@ -9,6 +9,7 @@ import type {OnyxData} from '@src/types/onyx/Request';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import * as LocalePhoneNumber from './LocalePhoneNumber';
import * as Localize from './Localize';
+import {areEmailsFromSamePrivateDomain} from './LoginUtils';
import * as UserUtils from './UserUtils';
type FirstAndLastName = {
@@ -370,6 +371,22 @@ function getUserNameByEmail(email: string, nameToDisplay: 'firstName' | 'display
return email;
}
+const getShortMentionIfFound = (displayText: string, userAccountID: string, currentUserPersonalDetails: OnyxEntry, 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) {
+ return displayText;
+ }
+
+ // If the emails are not in the same private domain, we also return the displayText
+ if (!areEmailsFromSamePrivateDomain(displayText, currentUserPersonalDetails?.login ?? '')) {
+ return displayText;
+ }
+
+ // Otherwise, the emails must be of the same private domain, so we should remove the domain part
+ return displayText.split('@').at(0);
+};
+
export {
isPersonalDetailsEmpty,
getDisplayNameOrDefault,
@@ -388,4 +405,5 @@ export {
getNewAccountIDsAndLogins,
getPersonalDetailsLength,
getUserNameByEmail,
+ getShortMentionIfFound,
};
diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index c5d29affb684..b2600ad985a3 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -74,7 +74,7 @@ import localeCompare from './LocaleCompare';
import {formatPhoneNumber} from './LocalePhoneNumber';
import {translateLocal} from './Localize';
import Log from './Log';
-import {areEmailsFromSamePrivateDomain, isEmailPublicDomain} from './LoginUtils';
+import {isEmailPublicDomain} from './LoginUtils';
// eslint-disable-next-line import/no-cycle
import ModifiedExpenseMessage from './ModifiedExpenseMessage';
import {linkingConfig} from './Navigation/linkingConfig';
@@ -82,7 +82,15 @@ import Navigation from './Navigation/Navigation';
import {rand64} from './NumberUtils';
import Parser from './Parser';
import Permissions from './Permissions';
-import {getAccountIDsByLogins, getDisplayNameOrDefault, getEffectiveDisplayName, getLoginsByAccountIDs, getPersonalDetailByEmail, getPersonalDetailsByIDs} from './PersonalDetailsUtils';
+import {
+ getAccountIDsByLogins,
+ getDisplayNameOrDefault,
+ getEffectiveDisplayName,
+ getLoginsByAccountIDs,
+ getPersonalDetailByEmail,
+ getPersonalDetailsByIDs,
+ getShortMentionIfFound,
+} from './PersonalDetailsUtils';
import {addSMSDomainIfPhoneNumber} from './PhoneNumber';
import {
arePaymentsEnabled,
@@ -4190,22 +4198,6 @@ function getInvoicePayerName(report: OnyxEntry, invoiceReceiverPolicy?:
return getPolicyName({report, policy: invoiceReceiverPolicy ?? allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiver?.policyID}`]});
}
-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) {
- return displayText;
- }
-
- // If the emails are not in the same private domain, we also return the displayText
- if (!areEmailsFromSamePrivateDomain(displayText, currentUserPersonalDetails?.login ?? '')) {
- return displayText;
- }
-
- // Otherwise, the emails must be of the same private domain, so we should remove the domain part
- return displayText.split('@').at(0);
-};
-
/**
* Parse html of reportAction into text
*/
@@ -4236,7 +4228,7 @@ function parseReportActionHtmlToText(reportAction: OnyxEntry, repo
}
}
- const mentionUserRegex = /(?:|><\/mention-user>))|(?:(.*?)<\/mention-user>)/gi;
+ const mentionUserRegex = /(?:|><\/mention-user>))/gi;
const accountIDToName: Record = {};
const accountIDs = Array.from(html.matchAll(mentionUserRegex), (mention) => Number(mention[1]));
const logins = getLoginsByAccountIDs(accountIDs);
@@ -4244,7 +4236,7 @@ function parseReportActionHtmlToText(reportAction: OnyxEntry, repo
const login = logins.at(index);
const user = allPersonalDetails?.[id];
const displayName = formatPhoneNumber(login ?? '') || getDisplayNameOrDefault(user);
- accountIDToName[id] = getShortMentionIfFound(displayName, id.toString(), login) ?? '';
+ accountIDToName[id] = getShortMentionIfFound(displayName, id.toString(), currentUserPersonalDetails, login) ?? '';
});
const textMessage = Str.removeSMSDomain(Parser.htmlToText(html, {reportIDToName, accountIDToName}));