8000 [Notifier][Bluesky] Add support for tags facet by romainneutron · Pull Request #59784 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Notifier][Bluesky] Add support for tags facet #59784

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

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ private function parseFacets(string $input): array
];
}

// partial/naive URL regex based on: https://github.com/bluesky-social/atproto/blob/main/packages/api/src/rich-text/util.ts
// https://github.com/bluesky-social/atproto/blob/main/packages/api/src/rich-text/detection.ts
$regex = '/(?:^|\s)(#[\p{L}\p{N}]+)/u';
foreach ($this->getMatchAndPosition($text, $regex) as $match) {
$facets[] = [
'index' => [
'byteStart' => $match['start'],
'byteEnd' => $match['end'],
], 8000
'features' => [
[
'$type' => 'app.bsky.richtext.facet#tag',
'tag' => substr($match['match'], 1),
],
],
];
}

return $facets;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,39 @@ public function testParseFacetsUrlWithEmoji()
$this->assertEquals($expected, $output);
}

public function testParseFacetsHashTags()
{
$input = 'Salut #test #123 #テスト http://bsky.app';
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you could update the URL http://bsky.app to use something like http://bsky.app#fragment to see if the regex doesn't catch the URL fragment as a hashtag. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Regarding URLs (and tags), this is already the default behavior when not using facets. Any benefits in doing it via facets?

$expected = [
[
'index' => ['byteStart' => 28, 'byteEnd' => 43],
'features' => [
['$type' => 'app.bsky.richtext.facet#link', 'uri' => 'http://bsky.app'],
],
],
[
'index' => ['byteStart' => 6, 'byteEnd' => 11],
'features' => [
['$type' => 'app.bsky.richtext.facet#tag', 'tag' => 'test'],
],
],
[
'index' => ['byteStart' => 12, 'byteEnd' => 16],
'features' => [
['$type' => 'app.bsky.richtext.facet#tag', 'tag' => '123'],
],
],
[
'index' => ['byteStart' => 17, 'byteEnd' => 27],
'features' => [
['$type' => 'app.bsky.richtext.facet#tag', 'tag' => 'テスト'],
],
],
];
$output = $this->parseFacets($input);
$this->assertEquals($expected, $output);
}

/**
* Example from https://github.com/bluesky-social/atproto-website/blob/main/examples/create_bsky_post.py.
*/
Expand Down
Loading
0