NotificationMailer: send to correct destinees

This commit is contained in:
Julien Fastré 2023-09-06 15:47:59 +02:00
parent f3fbd5314a
commit 40a72d9fca
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 17 additions and 13 deletions

View File

@ -1,6 +0,0 @@
kind: Fixed
body: Fix who receive reply notification when adding comment (recipees must receive
it, and sender not).
time: 2023-08-24T15:20:38.472382872+02:00
custom:
Issue: "137"

View File

@ -0,0 +1,5 @@
kind: Fixed
body: Do not send an email to creator twice when adding a comment to a notification
time: 2023-09-06T15:48:56.991246312+02:00
custom:
Issue: ""

View File

@ -40,13 +40,18 @@ class NotificationMailer
public function postPersistComment(NotificationComment $comment, PostPersistEventArgs $eventArgs): void
{
foreach (
array_merge(
$comment->getNotification()->getAddressees()->toArray(),
[$comment->getNotification()->getSender()]
) as $dest
) {
if (null !== $dest->getEmail() && $comment->getCreatedBy() === $dest) {
$dests = [$comment->getNotification()->getSender(), ...$comment->getNotification()->getAddressees()->toArray()];
$uniqueDests = [];
foreach ($dests as $dest) {
// avoid duplication
if (in_array(spl_object_hash($dest), $uniqueDests, true)) {
continue;
}
$uniqueDests[] = spl_object_hash($dest);
// do not send if the sender does not have any email, nor to the creator of the comment
if (null === $dest->getEmail() || $comment->getCreatedBy() === $dest) {
continue;
}
$email = new TemplatedEmail();