From a0b112e8db120087c4336a8cc3741e7418a19401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 28 Dec 2021 23:31:33 +0100 Subject: [PATCH] notificaiton: handle remove addressee and reset at the end of registering unread --- src/Bundle/ChillMainBundle/Entity/Notification.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index d7e7075ed..61c1c5926 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -196,13 +196,27 @@ class Notification $this->addUnreadBy($addressee); } + foreach ($this->removedAddresses as $addressee) { + $this->removeAddressee($addressee); + } + if (null !== $this->addressesOnLoad) { foreach ($this->addressees as $existingAddresse) { if (!$this->addressesOnLoad->contains($existingAddresse)) { $this->addUnreadBy($existingAddresse); } } + + foreach ($this->addressesOnLoad as $onLoadAddressee) { + if (!$this->addressees->contains($onLoadAddressee)) { + $this->removeUnreadBy($onLoadAddressee); + } + } } + + $this->removedAddresses = []; + $this->addedAddresses = []; + $this->addressesOnLoad = null; } public function removeAddressee(User $addressee): self