<?php
namespace App\Subscriber\Caching;
use App\Event\Messenger\AttachmentBoughtEvent;
use App\Event\Messenger\RouteReadEvent;
use Frivol\Common\Service\CacheService;
use App\Service\Client\Messenger\MessengerService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MessengerSubscriber implements EventSubscriberInterface
{
protected MessengerService $service;
protected CacheService $cacheService;
public function __construct(CacheService $cacheService, MessengerService $service)
{
$this->cacheService = $cacheService;
$this->service = $service;
}
public static function getSubscribedEvents()
{
return [
RouteReadEvent::class => [
['onRouteReadEvent', 0]
],
AttachmentBoughtEvent::class => [
['onAttachmentBoughtEvent', 0]
]
];
}
/**
* @param AttachmentBoughtEvent $event
* @return void
* @throws \Psr\Cache\InvalidArgumentException
*/
public function onAttachmentBoughtEvent(AttachmentBoughtEvent $event)
{
$this->cacheService->clearConversationCache($event->getConversation());
}
public function onRouteReadEvent(RouteReadEvent $event)
{
$this->service->markRouteAsRead($event->getConversation(), $event->getRoute());
}
}