Files
KanbanGit/app/Actions/Notifications/QueueNotificationEventDeliveries.php
Koda ad7ab48443
linter / quality (pull_request) Successful in 3m31s
tests / ci (8.4) (pull_request) Successful in 2m0s
Merge main into notification filters
2026-04-29 10:41:51 +00:00

51 lines
1.9 KiB
PHP

<?php
namespace App\Actions\Notifications;
use App\Enums\NotificationChannel;
use App\Enums\NotificationDeliveryStatus;
use App\Models\NotificationAction;
use App\Models\NotificationDeliveryLog;
class QueueNotificationEventDeliveries
{
public function __construct(
private readonly MatchNotificationFilters $matchNotificationFilters,
) {}
public function handle(NotificationEvent $event): void
{
$payload = $event->payload();
$eventType = $event->eventType();
NotificationAction::query()
->enabled()
->where('project_id', $payload->projectId())
->where('event_type', $eventType->value)
->get(['channel', 'filters', 'id'])
->each(function (NotificationAction $notificationAction) use ($event, $payload): void {
if (! $this->matchNotificationFilters->handle($notificationAction->filters ?? [], $payload)) {
return;
}
$notificationDeliveryLogId = null;
if (in_array($notificationAction->channel, [NotificationChannel::Discord, NotificationChannel::Webhook], true)) {
$notificationDeliveryLogId = NotificationDeliveryLog::query()->create([
'attempt_count' => 0,
'channel' => $notificationAction->channel,
'delivery_status' => NotificationDeliveryStatus::Pending,
'event_type' => $event->eventType(),
'notification_action_id' => $notificationAction->id,
'payload_metadata' => $payload->deliveryMetadata(),
])->id;
}
DeliverNotificationAction::dispatch(
notificationActionId: $notificationAction->id,
event: $event,
notificationDeliveryLogId: $notificationDeliveryLogId,
);
});
}
}