Skip to content

Commit

Permalink
send message notifier feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed Nov 18, 2023
1 parent 47ed18a commit 5989abc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
37 changes: 28 additions & 9 deletions packages/conversation/src/Service/NewMessageMailNotifier.php
Expand Up @@ -49,23 +49,44 @@ public function __construct(
*/
protected function getMessagesPostedSince(\DateTimeInterface $datetime)
{
$query = 'SELECT m FROM '.$this->message.' m WHERE m.host = :host AND m.createdAt > :lastNotificationTime';
$query = 'SELECT m FROM '.$this->message.' m WHERE m.authorEmail IS NULL AND m.host = :host AND m.createdAt > :lastNotificationTime';
$query = $this->em->createQuery($query)
->setParameter('lastNotificationTime', $datetime, 'datetime')
->setParameter('host', $this->host);

return $query->getResult(); // @phpstan-ignore-line
}

public function postPersist(): void
public function postPersist(Message $message): void
{
$this->send();
if (null === $message->getAuthorEmail()) {
// $this->send();

return;
}

$this->sendMessage($message);
}

/**
* @return bool|void
*/
public function send()
public function sendMessage(Message $message): void
{
$authorEmail = $message->getAuthorEmail() ?? throw new \Exception();

$templatedEmail = (new TemplatedEmail())
->subject(
$this->translator->trans('admin.conversation.notification.title.singular', ['%appName%' => $this->appName])
)
->from($this->emailFrom)
->to($this->emailTo)
->replyTo($authorEmail)
->text($message->getContent()
."\n\n---\n"
.'Envoyé depuis '.$message->getHost().' '.$message->getReferring());

$this->mailer->send($templatedEmail);
}

public function send(): void
{
if ('' === $this->emailTo) {
$this->logger->info('Not sending conversation notification : `conversation_notification_email_to` is not configured.');
Expand Down Expand Up @@ -106,7 +127,5 @@ public function send()

$lastTime->set();
$this->mailer->send($templatedEmail);

return true;
}
}
2 changes: 1 addition & 1 deletion packages/docs/content/roadmap.md
Expand Up @@ -8,8 +8,8 @@ parent: contribute
## BugFix && To finish

- [Core] https://github.com/jolicode/JoliTypo
- [Core/AdminBlockEditor] Related, RelatedToParent

- [Admin] Brouillon
- [Admin] Block (left column) for viewing Page subtitle and navigate in the content
- [Admin] Page : Code Editor for Autres paramêtres (yaml highlighting)
- [Admin] Implements htmx ?!
Expand Down
Binary file modified packages/skeleton/var/app.db
Binary file not shown.

0 comments on commit 5989abc

Please sign in to comment.