diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 96605a229e9..73132ceb853 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3658,6 +3658,23 @@ function addDomainToShortMention(mention: string): string | undefined { return undefined; } +/** + * Replaces all valid short mention found in a text to a full mention + * + * Example: + * "Hello \@example -> Hello \@example\@expensify.com" + */ +function completeShortMention(text: string): string { + return text.replace(CONST.REGEX.SHORT_MENTION, (match) => { + if (!Str.isValidMention(match)) { + return match; + } + const mention = match.substring(1); + const mentionWithDomain = addDomainToShortMention(mention); + return mentionWithDomain ? `@${mentionWithDomain}` : match; + }); +} + /** * For comments shorter than or equal to 10k chars, convert the comment from MD into HTML because that's how it is stored in the database * For longer comments, skip parsing, but still escape the text, and display plaintext for performance reasons. It takes over 40s to parse a 100k long string!! @@ -3669,14 +3686,7 @@ function getParsedComment(text: string, parsingDetails?: ParsingDetails): string isGroupPolicyReport = isReportInGroupPolicy(currentReport); } - const textWithMention = text.replace(CONST.REGEX.SHORT_MENTION, (match) => { - if (!Str.isValidMention(match)) { - return match; - } - const mention = match.substring(1); - const mentionWithDomain = addDomainToShortMention(mention); - return mentionWithDomain ? `@${mentionWithDomain}` : match; - }); + const textWithMention = completeShortMention(text); return text.length <= CONST.MAX_MARKUP_LENGTH ? Parser.replace(textWithMention, {shouldEscapeText: parsingDetails?.shouldEscapeText, disabledRules: isGroupPolicyReport ? [] : ['reportMentions']}) @@ -7146,6 +7156,7 @@ function isExported(reportActions: OnyxEntry) { export { addDomainToShortMention, + completeShortMention, areAllRequestsBeingSmartScanned, buildOptimisticAddCommentReportAction, buildOptimisticApprovedReportAction, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index ffabf3f36fb..2f4f47e9f81 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1535,10 +1535,12 @@ function handleUserDeletedLinksInHtml(newCommentText: string, originalCommentMar return newCommentText; } - const htmlForNewComment = Parser.replace(newCommentText, { + const textWithMention = ReportUtils.completeShortMention(newCommentText); + + const htmlForNewComment = Parser.replace(textWithMention, { extras: {videoAttributeCache}, }); - const removedLinks = Parser.getRemovedMarkdownLinks(originalCommentMarkdown, newCommentText); + const removedLinks = Parser.getRemovedMarkdownLinks(originalCommentMarkdown, textWithMention); return removeLinksFromHtml(htmlForNewComment, removedLinks); }