123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Listeners;
- use App\Events\ObjectActionCreate;
- use App\Models\Enums\ActionObjectType;
- use App\Models\Enums\NotificationObjectType;
- use App\Models\Enums\ObjectAction;
- use App\Models\Notification;
- use App\Models\NotificationRecord;
- use App\Repositories\ConfigRepository;
- use App\Services\Notification\ActionBrowser\NormalNotification;
- use App\Services\Notification\ActionBrowser\RequirementNotification;
- use App\Services\Notification\ActionBrowser\TaskNotification;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Queue\InteractsWithQueue;
- class SendActionBrowserNotification implements ShouldQueue
- {
- /**
- * Create the event listener.
- */
- public function __construct()
- {
- //
- }
- /**
- * Handle the event.
- */
- public function handle(ObjectActionCreate $event): void
- {
- if(! ConfigRepository::openBrowserNotification()){
- return;
- }
- $actionObjectType = ActionObjectType::tryFrom($event->action->object_type);
- $object = $actionObjectType->modelBuilder()->find($event->action->object_id);
- if (! $object) {
- return;
- }
- $notification = match ($actionObjectType) {
- ActionObjectType::PROJECT, ActionObjectType::CONTAINER => new NormalNotification($event->action, $object),
- ActionObjectType::REQUIREMENT => new RequirementNotification($event->action, $object),
- ActionObjectType::TASK => new TaskNotification($event->action, $object),
- default => null,
- };
- $notification?->handle();
- }
- public function shouldQueue(ObjectActionCreate $event): bool
- {
- $actionObjectType = ActionObjectType::tryFrom($event->action->object_type);
- $objectAction = ObjectAction::tryFrom($event->action->action);
- if (! $actionObjectType || !$objectAction) {
- return false;
- }
- return in_array($objectAction->value, $event->notificationSetting[$actionObjectType->value]['browser'] ?? []);
- }
- }
|