Skip to content

Commit

Permalink
Merge pull request #45504 from bernhardoj/fix/45435-short-mention-isn…
Browse files Browse the repository at this point in the history
…t-recognized-on-edit-message

Fix short mention isn't recognized when editing a message
  • Loading branch information
jasperhuangg committed Jul 20, 2024
2 parents fa738c6 + 32c6998 commit f3a8f73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
27 changes: 19 additions & 8 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!!
Expand All @@ -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']})
Expand Down Expand Up @@ -7146,6 +7156,7 @@ function isExported(reportActions: OnyxEntry<ReportActions>) {

export {
addDomainToShortMention,
completeShortMention,
areAllRequestsBeingSmartScanned,
buildOptimisticAddCommentReportAction,
buildOptimisticApprovedReportAction,
Expand Down
6 changes: 4 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit f3a8f73

Please sign in to comment.