src/Core/Application/EventSubscriber/Chat/ChatInvitedUserToChannelSubscriber.php line 36
<?phpdeclare(strict_types=1);namespace App\Core\Application\EventSubscriber\Chat;use App\Core\Application\Event\Chat\ChatInvitedUserToChannelEvent;use App\Core\Application\Service\RocketChat\RocketChatClientServiceInterface;use App\Core\Domain\Entity\Student\Student;use App\Core\Domain\Entity\User\User;use App\Core\Domain\Repository\ChatSetting\ChatChannelRepositoryInterface;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;class ChatInvitedUserToChannelSubscriber implements EventSubscriberInterface{private readonly RocketChatClientServiceInterface $rocketChatClientService;private readonly EntityManagerInterface $em;public function __construct(EntityManagerInterface $em,RocketChatClientServiceInterface $rocketChatClientService,private readonly ChatChannelRepositoryInterface $chatChannelRepository) {$this->rocketChatClientService = $rocketChatClientService;$this->em = $em;}public static function getSubscribedEvents(): array{return [ChatInvitedUserToChannelEvent::class => 'inviteUserToChannel',];}public function inviteUserToChannel(ChatInvitedUserToChannelEvent $event): void{$channelId = $event->channelId;$user = $event->user;if ($user instanceof Student) {$this->rocketChatClientService->inviteUserToChannel($user->getChatSetting()->getChatUserId(), $channelId);}if ($user instanceof User) {$this->rocketChatClientService->inviteUserToChannel($user->getChatSetting()->getChatUserId(), $channelId);}$chatChannel = $this->chatChannelRepository->findOneBy(['chat_channel_id' => $channelId]);$user->getChatSetting()->addChatChannel($chatChannel);$this->em->persist($user);}}