sender = new Address($mailerSenderEmail, $mailerSenderName); } /** * @throws TransportExceptionInterface * @throws \Exception * @throws ExceptionInterface */ public function __invoke(SendDomainEventNotif $message): void { /** @var WatchList $watchList */ $watchList = $this->watchListRepository->findOneBy(['token' => $message->watchListToken]); /** @var Domain $domain */ $domain = $this->domainRepository->findOneBy(['ldhName' => $message->ldhName]); /* * For each new event whose date is after the domain name update date (before the current domain name update) */ /** @var DomainEvent $event */ foreach ($domain->getEvents()->filter( fn ($event) => $message->updatedAt < $event->getDate() && $event->getDate() < new \DateTimeImmutable()) as $event ) { $watchListTriggers = $watchList->getWatchListTriggers() ->filter(fn ($trigger) => $trigger->getEvent() === $event->getAction()); /* * For each trigger, we perform the appropriate action: send email or send push notification (for now) */ /** @var WatchListTrigger $watchListTrigger */ foreach ($watchListTriggers->getIterator() as $watchListTrigger) { $this->logger->info('Action {event} has been detected on the domain name {ldhName}. A notification is sent to user {username}.', [ 'event' => $event->getAction(), 'ldhName' => $message->ldhName, 'username' => $watchList->getUser()->getUserIdentifier(), ]); $recipient = new Recipient($watchList->getUser()->getEmail()); $notification = new DomainUpdateNotification($this->sender, $event); if (TriggerAction::SendEmail == $watchListTrigger->getAction()) { $this->mailer->send($notification->asEmailMessage($recipient)->getMessage()); } elseif (TriggerAction::SendChat == $watchListTrigger->getAction()) { $webhookDsn = $watchList->getWebhookDsn(); if (null === $webhookDsn || 0 === count($webhookDsn)) { continue; } $this->chatNotificationService->sendChatNotification($watchList, $notification); } if ($this->influxdbEnabled) { $this->influxdbService->addDomainNotificationPoint($domain, TriggerAction::SendChat, true); } $this->statService->incrementStat('stats.alert.sent'); } } } }