src/Core/Application/EventSubscriber/Chat/ChatUserDeactivatedSubscriber.php line 29

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Core\Application\EventSubscriber\Chat;
  4. use App\Core\Application\Event\Chat\ChatUserDeactivatedEvent;
  5. use App\Core\Application\Service\RocketChat\RocketChatClientServiceInterface;
  6. use App\Core\Domain\Entity\Student\Student;
  7. use App\Core\Domain\Entity\User\User;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class ChatUserDeactivatedSubscriber implements EventSubscriberInterface
  10. {
  11.     private readonly RocketChatClientServiceInterface $rocketChatClientService;
  12.     public function __construct(RocketChatClientServiceInterface $rocketChatClientService)
  13.     {
  14.         $this->rocketChatClientService $rocketChatClientService;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             ChatUserDeactivatedEvent::class => 'deactivateUser',
  20.         ];
  21.     }
  22.     public function deactivateUser(ChatUserDeactivatedEvent $event): void
  23.     {
  24.         $user $event->user;
  25.         if ($user instanceof Student) {
  26.             $chatUserId $user->getChatSetting()->getChatUserId();
  27.         } elseif ($user instanceof User) {
  28.             $chatUserId $user->getChatSetting()->getChatUserId();
  29.         } else {
  30.             throw new \InvalidArgumentException('Invalid user object provided.');
  31.         }
  32.         $this->rocketChatClientService->setDeactivationUser($chatUserId);
  33.     }
  34. }