kbin-core/src/Service/Notification/MessageNotificationManager.php
Ernest Wiśniewski a5f15a0b55 Symfony upgrade
2023-04-15 15:06:09 +02:00

44 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Service\Notification;
use ApiPlatform\Api\IriConverterInterface;
use App\Entity\Message;
use App\Entity\MessageNotification;
use App\Entity\User;
use App\Factory\MagazineFactory;
use App\Repository\MagazineSubscriptionRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Mercure\HubInterface;
class MessageNotificationManager
{
use NotificationTrait;
public function __construct(
private readonly MagazineSubscriptionRepository $repository,
private readonly IriConverterInterface $iriConverter,
private readonly MagazineFactory $magazineFactory,
private readonly HubInterface $publisher,
private readonly EntityManagerInterface $entityManager
) {
}
public function send(Message $message, User $sender): void
{
$thread = $message->thread;
$usersToNotify = $thread->getOtherParticipants($sender);
foreach ($usersToNotify as $subscriber) {
$notify = new MessageNotification($subscriber, $message);
$this->entityManager->persist($notify);
// @todo Send push notification to user
}
$this->entityManager->flush();
}
}