Setup support for syndicating to Bluesky
This commit is contained in:
parent
5d6d611707
commit
cbbe87e23c
9 changed files with 204 additions and 9 deletions
63
app/Jobs/SyndicateNoteToBluesky.php
Normal file
63
app/Jobs/SyndicateNoteToBluesky.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Note;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class SyndicateNoteToBluesky implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(
|
||||
protected Note $note
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function handle(Client $guzzle): void
|
||||
{
|
||||
// We can only make the request if we have an access token
|
||||
if (config('bridgy.bluesky_token') === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make micropub request
|
||||
$response = $guzzle->request(
|
||||
'POST',
|
||||
'https://brid.gy/micropub',
|
||||
[
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . config('bridgy.bluesky_token'),
|
||||
],
|
||||
'json' => [
|
||||
'type' => ['h-entry'],
|
||||
'properties' => [
|
||||
'content' => [$this->note->getRawOriginal('note')],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// Parse for syndication URL
|
||||
if ($response->getStatusCode() === 201) {
|
||||
$this->note->bluesky_url = $response->getHeader('Location')[0];;
|
||||
$this->note->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace App\Services;
|
||||
|
||||
use App\Jobs\SendWebMentions;
|
||||
use App\Jobs\SyndicateNoteToBluesky;
|
||||
use App\Jobs\SyndicateNoteToMastodon;
|
||||
use App\Models\Media;
|
||||
use App\Models\Note;
|
||||
|
@ -53,6 +54,10 @@ class NoteService extends Service
|
|||
dispatch(new SyndicateNoteToMastodon($note));
|
||||
}
|
||||
|
||||
if (in_array('bluesky', $this->getSyndicationTargets($request), true)) {
|
||||
dispatch(new SyndicateNoteToBluesky($note));
|
||||
}
|
||||
|
||||
return $note;
|
||||
}
|
||||
|
||||
|
@ -156,12 +161,12 @@ class NoteService extends Service
|
|||
$mpSyndicateTo = Arr::wrap($mpSyndicateTo);
|
||||
foreach ($mpSyndicateTo as $uid) {
|
||||
$target = SyndicationTarget::where('uid', $uid)->first();
|
||||
if ($target && $target->service_name === 'Twitter') {
|
||||
$syndication[] = 'twitter';
|
||||
}
|
||||
if ($target && $target->service_name === 'Mastodon') {
|
||||
$syndication[] = 'mastodon';
|
||||
}
|
||||
if ($target && $target->service_name === 'Bluesky') {
|
||||
$syndication[] = 'bluesky';
|
||||
}
|
||||
}
|
||||
|
||||
return $syndication;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue