Refactor notification event payloads and listener naming
linter / quality (pull_request) Successful in 1m17s
tests / ci (8.4) (pull_request) Failing after 1m35s

This commit is contained in:
2026-04-25 21:54:42 +00:00
parent 20f89952e7
commit 61505ace23
16 changed files with 286 additions and 115 deletions
@@ -4,15 +4,12 @@ namespace App\Actions\Notifications;
use App\Enums\NotificationEventType;
use Carbon\CarbonImmutable;
use Illuminate\Contracts\Support\Arrayable;
/**
* @implements Arrayable<string, mixed>
*/
final readonly class TicketStatusChangedPayload implements Arrayable
final readonly class TicketStatusChangedPayload implements NotificationEventPayload
{
public NotificationEventType $eventType;
public function __construct(
public NotificationEventType $eventType,
public int $projectId,
public string $projectKey,
public string $projectName,
@@ -22,12 +19,51 @@ final readonly class TicketStatusChangedPayload implements Arrayable
public string $ticketUrl,
public ?int $actorId,
public ?string $actorName,
public ?int $fromStatusId,
public ?string $fromStatusLabel,
public int $fromStatusId,
public string $fromStatusLabel,
public int $toStatusId,
public string $toStatusLabel,
public CarbonImmutable $occurredAt,
) {}
) {
$this->eventType = NotificationEventType::TicketStatusChanged;
}
public function eventType(): NotificationEventType
{
return $this->eventType;
}
public function projectId(): int
{
return $this->projectId;
}
/**
* @return array<string, scalar|null>
*/
public function deliveryMetadata(): array
{
return [
'project_key' => $this->projectKey,
'ticket_key' => $this->ticketKey,
];
}
/**
* @return array<string, string>
*/
public function discordTemplateVariables(): array
{
return [
'$url' => $this->ticketUrl,
'$ticket_key' => $this->ticketKey,
'$ticket_title' => $this->ticketTitle,
'$project_name' => $this->projectName,
'$status_from' => $this->fromStatusLabel,
'$status_to' => $this->toStatusLabel,
'$actor_name' => $this->actorName ?? '',
];
}
/**
* @return array{
@@ -35,7 +71,7 @@ final readonly class TicketStatusChangedPayload implements Arrayable
* project: array{id: int, key: string, name: string},
* ticket: array{id: int, key: string, title: string},
* actor: array{id: int, name: string}|null,
* from: array{id: int, label: string}|null,
* from: array{id: int, label: string},
* to: array{id: int, label: string},
* ticket_url: string,
* occurred_at: string
@@ -61,12 +97,10 @@ final readonly class TicketStatusChangedPayload implements Arrayable
'id' => $this->actorId,
'name' => $this->actorName,
],
'from' => $this->fromStatusId === null || $this->fromStatusLabel === null
? null
: [
'id' => $this->fromStatusId,
'label' => $this->fromStatusLabel,
],
'from' => [
'id' => $this->fromStatusId,
'label' => $this->fromStatusLabel,
],
'to' => [
'id' => $this->toStatusId,
'label' => $this->toStatusLabel,