Skip to content

Commit

Permalink
feat(posts): support specifying a post's language
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Feb 10, 2024
1 parent cfba893 commit 5ca868b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/BlueskyPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,47 @@

namespace NotificationChannels\Bluesky;

use Illuminate\Support\Arr;
use NotificationChannels\Bluesky\RichText\Facets\Facet;

class BlueskyPost
{
private function __construct(
public string $text = '',
public array $facets = [],
public array $languages = [],
) {
}

public function toArray(): array
{
return [
return array_filter([
'text' => $this->text,
'facets' => array_map(
callback: fn (array|Facet $facet) => \is_array($facet) ? $facet : $facet->toArray(),
array: $this->facets,
),
];
'langs' => $this->languages,
]);
}

public static function make(): static
{
return new static();
}

/**
* Sets the language(s) of the post.
*
* @see https://www.docs.bsky.app/blog/create-post#setting-the-posts-language
*/
public function language(string|array $language): static
{
$this->languages = Arr::wrap($language);

return $this;
}

/**
* Adds a facet to the post. Note that most facets are resolved automatically.
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/BlueskyPostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
it('can be converted to an array', function () {
$post = BlueskyPost::make()
->text('foo')
->language(['en-US'])
->facet(new Facet(
range: [6, 20],
features: [
Expand All @@ -31,6 +32,7 @@
],
],
],
'langs' => ['en-US'],
]);
});

Expand Down

0 comments on commit 5ca868b

Please sign in to comment.