Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client-twitter): clean up mention deduplication #2185

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/client-twitter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -454,4 +454,4 @@ function splitParagraph(paragraph: string, maxLength: number): string[] {
const restoredChunks = restoreUrls(splittedChunks, placeholderMap);

return restoredChunks;
}
}
Loading