Skip to content

Commit 4697321

Browse files
committed
Add support for tags facet on Bluesky notifier
1 parent 99d7695 commit 4697321

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyTransport.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,24 @@ private function parseFacets(string $input): array
208208
];
209209
}
210210

211+
// partial/naive URL regex based on: https://github.com/bluesky-social/atproto/blob/main/packages/api/src/rich-text/util.ts
212+
// https://github.com/bluesky-social/atproto/blob/main/packages/api/src/rich-text/detection.ts
213+
$regex = '/(?:^|\s)(#[\p{L}\p{N}]+)/u';
214+
foreach ($this->getMatchAndPosition($text, $regex) as $match) {
215+
$facets[] = [
216+
'index' => [
217+
'byteStart' => $match['start'],
218+
'byteEnd' => $match['end'],
219+
],
220+
'features' => [
221+
[
222+
'$type' => 'app.bsky.richtext.facet#tag',
223+
'tag' => $match['match'],
224+
],
225+
],
226+
];
227+
}
228+
211229
return $facets;
212230
}
213231

src/Symfony/Component/Notifier/Bridge/Bluesky/Tests/BlueskyTransportTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,39 @@ public function testParseFacetsUrlWithEmoji()
238238
$this->assertEquals($expected, $output);
239239
}
240240

241+
public function testParseFacetsHashTags()
242+
{
243+
$input = 'Salut #test #123 #テスト http://bsky.app';
244+
$expected = [
245+
[
246+
'index' => ['byteStart' => 28, 'byteEnd' => 43],
247+
'features' => [
248+
['$type' => 'app.bsky.richtext.facet#link', 'uri' => 'http://bsky.app'],
249+
],
250+
],
251+
[
252+
'index' => ['byteStart' => 6, 'byteEnd' => 11],
253+
'features' => [
254+
['$type' => 'app.bsky.richtext.facet#tag', 'tag' => '#test'],
255+
],
256+
],
257+
[
258+
'index' => ['byteStart' => 12, 'byteEnd' => 16],
259+
'features' => [
260+
['$type' => 'app.bsky.richtext.facet#tag', 'tag' => '#123'],
261+
],
262+
],
263+
[
264+
'index' => ['byteStart' => 17, 'byteEnd' => 27],
265+
'features' => [
266+
['$type' => 'app.bsky.richtext.facet#tag', 'tag' => '#テスト'],
267+
],
268+
],
269+
];
270+
$output = $this->parseFacets($input);
271+
$this->assertEquals($expected, $output);
272+
}
273+
241274
/**
242275
* Example from https://github.com/bluesky-social/atproto-website/blob/main/examples/create_bsky_post.py.
243276
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy