Skip to content

feat: Implement at-mention detection for Bluesky posts#104

Merged
nzakas merged 3 commits intomainfrom
copilot/fix-103
Jul 3, 2025
Merged

feat: Implement at-mention detection for Bluesky posts#104
nzakas merged 3 commits intomainfrom
copilot/fix-103

Conversation

Copy link
Contributor

Copilot AI commented Jul 3, 2025

This PR implements at-mention detection for BlueSky posts, allowing mentions like @username to be properly converted to clickable links in BlueSky posts.

Changes Made

Core Implementation

  • Added BLUESKY_MENTION_FACET constant for the BlueSky mention facet type (app.bsky.richtext.facet#mention)
  • Created BlueSkyMentionFacetFeature class to represent mention facets in the BlueSky API format
  • Added MentionDetails typedef for type safety
  • Implemented detectMentions() function that uses a robust regex pattern to detect valid mentions
  • Updated detectFacets() to include mention detection alongside existing URL and hashtag detection

Mention Detection Features

  • Detects various mention formats: @username, @user.name, @user-name
  • Handles mentions in different contexts:
    • Standalone: @alice
    • In parentheses: (@username)
    • Mixed with other content: Check @user for #javascript tips!
  • Validates mention format (rejects @123, @., @@, etc.)
  • Properly calculates byte offsets for BlueSky API compatibility

Testing

  • Added comprehensive test suite with 29 new test cases covering:
    • Valid mention detection in various positions
    • Multiple mentions in the same text
    • Mentions combined with URLs and hashtags
    • Invalid mention rejection
    • Proper byte location calculation

Example Usage

import { detectFacets } from './src/util/bluesky-facets.js';

const text = "Hello @alice and @bob, check out https://example.com!";
const facets = detectFacets(text);
// Now includes mention facets for @alice and @bob along with URL facet

Future Enhancement

The current implementation stores handles in the did field as noted in the issue. A future enhancement will resolve handles to actual DIDs via the BlueSky API and validate mention existence before posting.

Testing Results

  • ✅ All 267 tests passing
  • ✅ ESLint passes with no issues
  • ✅ Manual verification confirms mention detection works correctly
  • ✅ Existing functionality unchanged

Fixes #103.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
Copilot AI changed the title [WIP] Detect at-mentions in BlueSky Implement at-mention detection for BlueSky posts Jul 3, 2025
Copilot AI requested a review from nzakas July 3, 2025 13:15
Copilot finished work on behalf of nzakas July 3, 2025 13:15
index: tag.byteRange,
features: [new BlueSkyTagFacetFeature(tag.tag)],
})),
...detectMentions(text).map(mention => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This correctly finds at-mentions, but we really do need to use the actual did when we start the request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right. The current implementation correctly detects mentions and stores handles in the did field as a placeholder. The next step will be to resolve these handles to actual DIDs via the BlueSky API before making the post request. I've noted this in the class documentation for future enhancement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make that change now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented DID resolution for BlueSky mentions. The changes include:

  • Added resolveHandle() function to resolve handles to DIDs via the BlueSky API
  • Updated the posting flow to resolve mention handles before creating posts
  • Added comprehensive tests covering both successful resolution and graceful failure handling
  • Mentions that fail to resolve are silently skipped to prevent post failures

All 269 tests are passing. Commit: f681245

Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
Copilot finished work on behalf of nzakas July 3, 2025 15:34
@nzakas nzakas changed the title Implement at-mention detection for BlueSky posts feat: Implement at-mention detection for Bluesky posts Jul 3, 2025
@nzakas nzakas marked this pull request as ready for review July 3, 2025 21:22
@nzakas nzakas merged commit a04f786 into main Jul 3, 2025
15 checks passed
@nzakas nzakas deleted the copilot/fix-103 branch July 3, 2025 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect at-mentions in BlueSky

2 participants