From fd8cd792b3036979986ea9c361b3a48c1fa27e7f Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 17 Jul 2024 01:35:00 +0800 Subject: [PATCH 1/3] fix short mention isn't recognized when editing a message --- src/libs/ReportUtils.ts | 21 +++++++++++++-------- src/libs/actions/Report.ts | 6 ++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index e29a2c14e3c4..b004dd5866a8 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3654,6 +3654,17 @@ function addDomainToShortMention(mention: string): string | undefined { return undefined; } +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!! @@ -3665,14 +3676,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']}) @@ -7103,6 +7107,7 @@ function findPolicyExpenseChatByPolicyID(policyID: string): OnyxEntry { export { addDomainToShortMention, + completeShortMention, areAllRequestsBeingSmartScanned, buildOptimisticAddCommentReportAction, buildOptimisticApprovedReportAction, diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 1c863d485fbe..cc9a7c807c6f 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -1519,10 +1519,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); } From de63de4b780017e4682cd2695cddfbb002d92504 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 18 Jul 2024 13:07:05 +0800 Subject: [PATCH 2/3] add comment --- src/libs/ReportUtils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ad5e8286b9b3..005214166258 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3660,6 +3660,9 @@ function addDomainToShortMention(mention: string): string | undefined { return undefined; } +/** + * Replaces all valid short mention found in a text to a full mention + */ function completeShortMention(text: string): string { return text.replace(CONST.REGEX.SHORT_MENTION, (match) => { if (!Str.isValidMention(match)) { From 32c699865e0fb5d5b432ac9b967f12ae98696659 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 19 Jul 2024 12:20:41 +0800 Subject: [PATCH 3/3] update comment --- src/libs/ReportUtils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 005214166258..e9677ee7a616 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3662,6 +3662,9 @@ function addDomainToShortMention(mention: string): string | 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) => {