ledgerrz/app/Notifications/NewActivityNotification.php
Daan Meijer 77c3e34d5b
Some checks failed
linter / quality (push) Failing after 1m2s
tests / ci (8.3) (push) Failing after 47s
tests / ci (8.4) (push) Failing after 1m5s
tests / ci (8.5) (push) Failing after 1m5s
polishing
2026-06-22 15:21:27 +02:00

73 lines
1.6 KiB
PHP

<?php
namespace App\Notifications;
use App\Models\Chat;
use App\Models\Message;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
use NotificationChannels\WebPush\WebPushMessage;
class NewActivityNotification extends Notification
{
use Queueable;
public $activity;
/**
* Create a new notification instance.
*/
public function __construct($activity)
{
$this->activity = $activity;
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return [WebPushChannel::class];
}
/**
* Get the web push representation of the notification.
*/
public function toWebPush(object $notifiable): WebPushMessage
{
$result = (new WebPushMessage)
->title('New Activity')
->icon('/apple-touch-icon.png')
->body($this->activity['content'])
->action('View', 'view')
->data(['url' => $this->activity['url']]);
switch (get_class($this->activity)) {
case Message::class:
/** @var Chat $chat */
$chat = $this->activity->chat;
$result->data(['url' => $chat->subjectUrl]);
break;
}
return $result;
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
//
];
}
}