src/Core/Application/EventSubscriber/Chat/ChatUserTokenGeneratedSubscriber.php line 30
<?phpdeclare(strict_types=1);namespace App\Core\Application\EventSubscriber\Chat;use App\Core\Application\Event\Chat\ChatUserTokenGeneratedEvent;use App\Core\Application\Service\RocketChat\RocketChatClientServiceInterface;use App\Core\Domain\Entity\ChatSetting\ChatUserInterface;use App\Core\Domain\Entity\Student\Student;use App\Core\Domain\Entity\User\User;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class ChatUserTokenGeneratedSubscriber implements EventSubscriberInterface{private readonly RocketChatClientServiceInterface $rocketChatClientService;public function __construct(RocketChatClientServiceInterface $rocketChatClientService){$this->rocketChatClientService = $rocketChatClientService;}public static function getSubscribedEvents(): array{return [ChatUserTokenGeneratedEvent::class => 'createToken',];}public function createToken(ChatUserTokenGeneratedEvent $event): void{$user = $event->user;$token = '';if ($user instanceof Student) {$token = $this->rocketChatClientService->createToken($user->getChatSetting()->getChatUserId());}if ($user instanceof User) {$token = $this->rocketChatClientService->createToken($user->getChatSetting()->getChatUserId());}$user->getChatSetting()->setToken($token);}}