Send Brrr push notifications for new webmentions
Dispatches a queued job to POST to a configured Brrr webhook whenever a brand-new webmention is saved, so replies/likes/reposts show up as push notifications instead of requiring a manual check of the site.
This commit is contained in:
parent
31c49ac3fc
commit
f9f2744fad
6 changed files with 138 additions and 0 deletions
56
app/Jobs/NotifyBrrrOfWebMention.php
Normal file
56
app/Jobs/NotifyBrrrOfWebMention.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\WebMention;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class NotifyBrrrOfWebMention implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(
|
||||
protected WebMention $webMention
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$webhookUrl = config('services.brrr.webhook_url');
|
||||
|
||||
if (blank($webhookUrl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Http::post($webhookUrl, [
|
||||
'title' => $this->title(),
|
||||
'message' => "From {$this->webMention->source}",
|
||||
'open_url' => $this->webMention->target,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a notification title based on the webmention type.
|
||||
*/
|
||||
private function title(): string
|
||||
{
|
||||
return match ($this->webMention->type) {
|
||||
'in-reply-to' => 'New reply',
|
||||
'like-of' => 'New like',
|
||||
'repost-of' => 'New repost',
|
||||
default => 'New webmention',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -96,6 +96,7 @@ class ProcessWebMention implements ShouldQueue
|
|||
$webmention->type = $type;
|
||||
$webmention->mf2 = json_encode($microformats);
|
||||
$webmention->save();
|
||||
dispatch(new NotifyBrrrOfWebMention($webmention));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue