diff options
author | Richard Steinmetz <richard@steinmetz.cloud> | 2022-11-01 15:49:54 +0100 |
---|---|---|
committer | Richard Steinmetz <richard@steinmetz.cloud> | 2022-11-04 16:24:57 +0100 |
commit | 304b71647f6aad9d6fc0caa775c3c91ba1724269 (patch) | |
tree | 68f8220b173fa1a0beeec79758b8439868344e37 /apps/dav/lib/CalDAV/Reminder | |
parent | f53abd3995cffcc0c0a3c5d9be80d993242d9b4e (diff) | |
download | nextcloud-server-304b71647f6aad9d6fc0caa775c3c91ba1724269.tar.gz nextcloud-server-304b71647f6aad9d6fc0caa775c3c91ba1724269.zip |
Fix duplicate event email notifications
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'apps/dav/lib/CalDAV/Reminder')
5 files changed, 38 insertions, 4 deletions
diff --git a/apps/dav/lib/CalDAV/Reminder/INotificationProvider.php b/apps/dav/lib/CalDAV/Reminder/INotificationProvider.php index a6b439c0b4f..505960ed662 100644 --- a/apps/dav/lib/CalDAV/Reminder/INotificationProvider.php +++ b/apps/dav/lib/CalDAV/Reminder/INotificationProvider.php @@ -8,6 +8,7 @@ declare(strict_types=1); * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Georg Ehrke <oc.list@georgehrke.com> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Richard Steinmetz <richard@steinmetz.cloud> * * @license GNU AGPL version 3 or any later version * @@ -42,10 +43,12 @@ interface INotificationProvider { * * @param VEvent $vevent * @param string $calendarDisplayName + * @param string[] $principalEmailAddresses All email addresses associated to the principal owning the calendar object * @param IUser[] $users * @return void */ public function send(VEvent $vevent, string $calendarDisplayName, + array $principalEmailAddresses, array $users = []): void; } diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php index 49cf36f98ac..6986328facd 100644 --- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php +++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php @@ -10,6 +10,7 @@ declare(strict_types=1); * @author Georg Ehrke <oc.list@georgehrke.com> * @author Joas Schilling <coding@schilljs.com> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Richard Steinmetz <richard@steinmetz.cloud> * * @license GNU AGPL version 3 or any later version * @@ -82,11 +83,13 @@ abstract class AbstractProvider implements INotificationProvider { * * @param VEvent $vevent * @param string $calendarDisplayName + * @param string[] $principalEmailAddresses * @param IUser[] $users * @return void */ abstract public function send(VEvent $vevent, string $calendarDisplayName, + array $principalEmailAddresses, array $users = []): void; /** diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php index d4aea6215ea..c2e68605d17 100644 --- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php +++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php @@ -71,16 +71,28 @@ class EmailProvider extends AbstractProvider { * * @param VEvent $vevent * @param string $calendarDisplayName + * @param string[] $principalEmailAddresses * @param array $users * @throws \Exception */ public function send(VEvent $vevent, string $calendarDisplayName, + array $principalEmailAddresses, array $users = []):void { $fallbackLanguage = $this->getFallbackLanguage(); + $organizerEmailAddress = null; + if (isset($vevent->ORGANIZER)) { + $organizerEmailAddress = $this->getEMailAddressOfAttendee($vevent->ORGANIZER); + } + $emailAddressesOfSharees = $this->getEMailAddressesOfAllUsersWithWriteAccessToCalendar($users); - $emailAddressesOfAttendees = $this->getAllEMailAddressesFromEvent($vevent); + $emailAddressesOfAttendees = []; + if (count($principalEmailAddresses) === 0 + || ($organizerEmailAddress && in_array($organizerEmailAddress, $principalEmailAddresses, true)) + ) { + $emailAddressesOfAttendees = $this->getAllEMailAddressesFromEvent($vevent); + } // Quote from php.net: // If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php index cb873020c38..833d74079aa 100644 --- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php +++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php @@ -10,6 +10,7 @@ declare(strict_types=1); * @author Georg Ehrke <oc.list@georgehrke.com> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Citharel <nextcloud@tcit.fr> + * @author Richard Steinmetz <richard@steinmetz.cloud> * * @license GNU AGPL version 3 or any later version * @@ -73,11 +74,13 @@ class PushProvider extends AbstractProvider { * * @param VEvent $vevent * @param string $calendarDisplayName + * @param string[] $principalEmailAddresses * @param IUser[] $users * @throws \Exception */ public function send(VEvent $vevent, - string $calendarDisplayName = null, + string $calendarDisplayName, + array $principalEmailAddresses, array $users = []):void { if ($this->config->getAppValue('dav', 'sendEventRemindersPush', 'no') !== 'yes') { return; diff --git a/apps/dav/lib/CalDAV/Reminder/ReminderService.php b/apps/dav/lib/CalDAV/Reminder/ReminderService.php index 2a065469052..3fb8cf9ebe5 100644 --- a/apps/dav/lib/CalDAV/Reminder/ReminderService.php +++ b/apps/dav/lib/CalDAV/Reminder/ReminderService.php @@ -11,6 +11,7 @@ declare(strict_types=1); * @author Joas Schilling <coding@schilljs.com> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Citharel <nextcloud@tcit.fr> + * @author Richard Steinmetz <richard@steinmetz.cloud> * * @license GNU AGPL version 3 or any later version * @@ -32,6 +33,7 @@ namespace OCA\DAV\CalDAV\Reminder; use DateTimeImmutable; use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\Connector\Sabre\Principal; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IConfig; use OCP\IGroup; @@ -76,6 +78,9 @@ class ReminderService { /** @var LoggerInterface */ private $logger; + /** @var Principal */ + private $principalConnector; + public const REMINDER_TYPE_EMAIL = 'EMAIL'; public const REMINDER_TYPE_DISPLAY = 'DISPLAY'; public const REMINDER_TYPE_AUDIO = 'AUDIO'; @@ -98,7 +103,8 @@ class ReminderService { CalDavBackend $caldavBackend, ITimeFactory $timeFactory, IConfig $config, - LoggerInterface $logger) { + LoggerInterface $logger, + Principal $principalConnector) { $this->backend = $backend; $this->notificationProviderManager = $notificationProviderManager; $this->userManager = $userManager; @@ -107,6 +113,7 @@ class ReminderService { $this->timeFactory = $timeFactory; $this->config = $config; $this->logger = $logger; + $this->principalConnector = $principalConnector; } /** @@ -175,12 +182,18 @@ class ReminderService { $users[] = $user; } + $userPrincipalEmailAddresses = []; + $userPrincipal = $this->principalConnector->getPrincipalByPath($reminder['principaluri']); + if ($userPrincipal) { + $userPrincipalEmailAddresses = $this->principalConnector->getEmailAddressesOfPrincipal($userPrincipal); + } + $this->logger->debug('Reminder {id} will be sent to {numUsers} users', [ 'id' => $reminder['id'], 'numUsers' => count($users), ]); $notificationProvider = $this->notificationProviderManager->getProvider($reminder['type']); - $notificationProvider->send($vevent, $reminder['displayname'], $users); + $notificationProvider->send($vevent, $reminder['displayname'], $userPrincipalEmailAddresses, $users); $this->deleteOrProcessNext($reminder, $vevent); } |