From 6d903bd345da2a32d519f04ac2f767a542653862 Mon Sep 17 00:00:00 2001 From: Nuri Hodges Date: Sun, 12 Jan 2025 09:13:51 +0100 Subject: [PATCH] fix(client-twitter): clean up mention deduplication --- packages/client-twitter/src/utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/client-twitter/src/utils.ts b/packages/client-twitter/src/utils.ts index 7f5be1cb5ca..0f2c125ed12 100644 --- a/packages/client-twitter/src/utils.ts +++ b/packages/client-twitter/src/utils.ts @@ -412,19 +412,19 @@ function deduplicateMentions(paragraph: string) { } // Extract mentions from the match groups - let mentions = matches.slice(1).filter(Boolean) as string[]; + let mentions = matches.slice(0, 1)[0].trim().split(' ') // Deduplicate mentions mentions = [...new Set(mentions)]; // Reconstruct the string with deduplicated mentions - const uniqueMentionsString = `@${mentions.join(' ')}`; + const uniqueMentionsString = mentions.join(' '); // Find where the mentions end in the original string const endOfMentions = paragraph.indexOf(matches[0]) + matches[0].length; // Construct the result by combining unique mentions with the rest of the string - return uniqueMentionsString + paragraph.slice(endOfMentions); + return uniqueMentionsString + ' ' + paragraph.slice(endOfMentions); } function restoreUrls( @@ -454,4 +454,4 @@ function splitParagraph(paragraph: string, maxLength: number): string[] { const restoredChunks = restoreUrls(splittedChunks, placeholderMap); return restoredChunks; -} \ No newline at end of file +}