aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV/Reminder/NotificationProvider
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/CalDAV/Reminder/NotificationProvider')
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php73
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/AudioProvider.php21
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php197
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/ProviderNotAvailableException.php21
-rw-r--r--apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php80
5 files changed, 113 insertions, 279 deletions
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
index 044e5fac4e2..94edff98e52 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AbstractProvider.php
@@ -3,39 +3,18 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019, Thomas Citharel
- * @copyright Copyright (c) 2019, Georg Ehrke
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
use OCA\DAV\CalDAV\Reminder\INotificationProvider;
use OCP\IConfig;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory;
+use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VEvent;
use Sabre\VObject\DateTimeParser;
use Sabre\VObject\Property;
@@ -50,51 +29,33 @@ abstract class AbstractProvider implements INotificationProvider {
/** @var string */
public const NOTIFICATION_TYPE = '';
- /** @var ILogger */
- protected $logger;
-
- /** @var L10NFactory */
- protected $l10nFactory;
-
/** @var IL10N[] */
private $l10ns;
/** @var string */
private $fallbackLanguage;
- /** @var IURLGenerator */
- protected $urlGenerator;
-
- /** @var IConfig */
- protected $config;
-
- /**
- * @param ILogger $logger
- * @param L10NFactory $l10nFactory
- * @param IConfig $config
- * @param IUrlGenerator $urlGenerator
- */
- public function __construct(ILogger $logger,
- L10NFactory $l10nFactory,
- IURLGenerator $urlGenerator,
- IConfig $config) {
- $this->logger = $logger;
- $this->l10nFactory = $l10nFactory;
- $this->urlGenerator = $urlGenerator;
- $this->config = $config;
+ public function __construct(
+ protected LoggerInterface $logger,
+ protected L10NFactory $l10nFactory,
+ protected IURLGenerator $urlGenerator,
+ protected IConfig $config,
+ ) {
}
/**
* Send notification
*
* @param VEvent $vevent
- * @param string $calendarDisplayName
+ * @param string|null $calendarDisplayName
+ * @param string[] $principalEmailAddresses
* @param IUser[] $users
* @return void
*/
abstract public function send(VEvent $vevent,
- string $calendarDisplayName,
- array $users = []): void;
+ ?string $calendarDisplayName,
+ array $principalEmailAddresses,
+ array $users = []): void;
/**
* @return string
@@ -139,7 +100,7 @@ abstract class AbstractProvider implements INotificationProvider {
*/
private function getStatusOfEvent(VEvent $vevent):string {
if ($vevent->STATUS) {
- return (string) $vevent->STATUS;
+ return (string)$vevent->STATUS;
}
// Doesn't say so in the standard,
@@ -189,4 +150,8 @@ abstract class AbstractProvider implements INotificationProvider {
return clone $vevent->DTSTART;
}
+
+ protected function getCalendarDisplayNameFallback(string $lang): string {
+ return $this->getL10NForLang($lang)->t('Untitled calendar');
+ }
}
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AudioProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AudioProvider.php
index 4b369b34dc0..01d51489a3b 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AudioProvider.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/AudioProvider.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019, Georg Ehrke
- *
- * @author Georg Ehrke <oc.list@georgehrke.com>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
index 456b9f8b42d..0fd39a9e459 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php
@@ -3,42 +3,22 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019, Thomas Citharel
- * @copyright Copyright (c) 2019, Georg Ehrke
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Richard Steinmetz <richard@steinmetz.cloud>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Citharel <nextcloud@tcit.fr>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
use DateTime;
use OCP\IConfig;
use OCP\IL10N;
-use OCP\ILogger;
use OCP\IURLGenerator;
+use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory;
+use OCP\Mail\Headers\AutoSubmitted;
use OCP\Mail\IEMailTemplate;
use OCP\Mail\IMailer;
+use OCP\Util;
+use Psr\Log\LoggerInterface;
use Sabre\VObject;
use Sabre\VObject\Component\VEvent;
use Sabre\VObject\Parameter;
@@ -50,44 +30,46 @@ use Sabre\VObject\Property;
* @package OCA\DAV\CalDAV\Reminder\NotificationProvider
*/
class EmailProvider extends AbstractProvider {
-
/** @var string */
public const NOTIFICATION_TYPE = 'EMAIL';
- /** @var IMailer */
- private $mailer;
-
- /**
- * @param IConfig $config
- * @param IMailer $mailer
- * @param ILogger $logger
- * @param L10NFactory $l10nFactory
- * @param IUrlGenerator $urlGenerator
- */
- public function __construct(IConfig $config,
- IMailer $mailer,
- ILogger $logger,
- L10NFactory $l10nFactory,
- IURLGenerator $urlGenerator) {
+ public function __construct(
+ IConfig $config,
+ private IMailer $mailer,
+ LoggerInterface $logger,
+ L10NFactory $l10nFactory,
+ IURLGenerator $urlGenerator,
+ ) {
parent::__construct($logger, $l10nFactory, $urlGenerator, $config);
- $this->mailer = $mailer;
}
/**
* Send out notification via email
*
* @param VEvent $vevent
- * @param string $calendarDisplayName
+ * @param string|null $calendarDisplayName
+ * @param string[] $principalEmailAddresses
* @param array $users
* @throws \Exception
*/
public function send(VEvent $vevent,
- string $calendarDisplayName,
- array $users = []):void {
+ ?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.
@@ -105,12 +87,12 @@ class EmailProvider extends AbstractProvider {
$lang = $fallbackLanguage;
}
$l10n = $this->getL10NForLang($lang);
- $fromEMail = \OCP\Util::getDefaultEmailAddress('reminders-noreply');
+ $fromEMail = Util::getDefaultEmailAddress('reminders-noreply');
$template = $this->mailer->createEMailTemplate('dav.calendarReminder');
$template->addHeader();
$this->addSubjectAndHeading($template, $l10n, $vevent);
- $this->addBulletList($template, $l10n, $calendarDisplayName, $vevent);
+ $this->addBulletList($template, $l10n, $calendarDisplayName ?? $this->getCalendarDisplayNameFallback($lang), $vevent);
$template->addFooter();
foreach ($emailAddresses as $emailAddress) {
@@ -126,6 +108,7 @@ class EmailProvider extends AbstractProvider {
}
$message->setTo([$emailAddress]);
$message->useTemplate($template);
+ $message->setAutoSubmitted(AutoSubmitted::VALUE_AUTO_GENERATED);
try {
$failed = $this->mailer->send($message);
@@ -133,7 +116,7 @@ class EmailProvider extends AbstractProvider {
$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]);
}
} catch (\Exception $ex) {
- $this->logger->logException($ex, ['app' => 'dav']);
+ $this->logger->error($ex->getMessage(), ['app' => 'dav', 'exception' => $ex]);
}
}
}
@@ -156,9 +139,9 @@ class EmailProvider extends AbstractProvider {
* @param array $eventData
*/
private function addBulletList(IEMailTemplate $template,
- IL10N $l10n,
- string $calendarDisplayName,
- VEvent $vevent):void {
+ IL10N $l10n,
+ string $calendarDisplayName,
+ VEvent $vevent):void {
$template->addBodyListItem($calendarDisplayName, $l10n->t('Calendar:'),
$this->getAbsoluteImagePath('actions/info.png'));
@@ -166,19 +149,15 @@ class EmailProvider extends AbstractProvider {
$this->getAbsoluteImagePath('places/calendar.png'));
if (isset($vevent->LOCATION)) {
- $template->addBodyListItem((string) $vevent->LOCATION, $l10n->t('Where:'),
+ $template->addBodyListItem((string)$vevent->LOCATION, $l10n->t('Where:'),
$this->getAbsoluteImagePath('actions/address.png'));
}
if (isset($vevent->DESCRIPTION)) {
- $template->addBodyListItem((string) $vevent->DESCRIPTION, $l10n->t('Description:'),
+ $template->addBodyListItem((string)$vevent->DESCRIPTION, $l10n->t('Description:'),
$this->getAbsoluteImagePath('actions/more.png'));
}
}
- /**
- * @param string $path
- * @return string
- */
private function getAbsoluteImagePath(string $path):string {
return $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath('core', $path)
@@ -201,7 +180,7 @@ class EmailProvider extends AbstractProvider {
$organizerEMail = substr($organizer->getValue(), 7);
- if ($organizerEMail === false || !$this->mailer->validateMailAddress($organizerEMail)) {
+ if (!$this->mailer->validateMailAddress($organizerEMail)) {
return null;
}
@@ -214,12 +193,11 @@ class EmailProvider extends AbstractProvider {
}
/**
- * @param array $emails
- * @param string $defaultLanguage
- * @return array
+ * @param array<string, array{LANG?: string}> $emails
+ * @return array<string, string[]>
*/
private function sortEMailAddressesByLanguage(array $emails,
- string $defaultLanguage):array {
+ string $defaultLanguage):array {
$sortedByLanguage = [];
foreach ($emails as $emailAddress => $parameters) {
@@ -241,7 +219,7 @@ class EmailProvider extends AbstractProvider {
/**
* @param VEvent $vevent
- * @return array
+ * @return array<string, array{LANG?: string}>
*/
private function getAllEMailAddressesFromEvent(VEvent $vevent):array {
$emailAddresses = [];
@@ -272,7 +250,10 @@ class EmailProvider extends AbstractProvider {
$emailAddressesOfDelegates = $delegates->getParts();
foreach ($emailAddressesOfDelegates as $addressesOfDelegate) {
if (strcasecmp($addressesOfDelegate, 'mailto:') === 0) {
- $emailAddresses[substr($addressesOfDelegate, 7)] = [];
+ $delegateEmail = substr($addressesOfDelegate, 7);
+ if ($this->mailer->validateMailAddress($delegateEmail)) {
+ $emailAddresses[$delegateEmail] = [];
+ }
}
}
@@ -284,7 +265,7 @@ class EmailProvider extends AbstractProvider {
$properties = [];
$langProp = $attendee->offsetGet('LANG');
- if ($langProp instanceof VObject\Parameter) {
+ if ($langProp instanceof VObject\Parameter && $langProp->getValue() !== null) {
$properties['LANG'] = $langProp->getValue();
}
@@ -294,18 +275,15 @@ class EmailProvider extends AbstractProvider {
}
if (isset($vevent->ORGANIZER) && $this->hasAttendeeMailURI($vevent->ORGANIZER)) {
- $emailAddresses[$this->getEMailAddressOfAttendee($vevent->ORGANIZER)] = [];
+ $organizerEmailAddress = $this->getEMailAddressOfAttendee($vevent->ORGANIZER);
+ if ($organizerEmailAddress !== null) {
+ $emailAddresses[$organizerEmailAddress] = [];
+ }
}
return $emailAddresses;
}
-
-
- /**
- * @param VObject\Property $attendee
- * @return string
- */
private function getCUTypeOfAttendee(VObject\Property $attendee):string {
$cuType = $attendee->offsetGet('CUTYPE');
if ($cuType instanceof VObject\Parameter) {
@@ -315,10 +293,6 @@ class EmailProvider extends AbstractProvider {
return 'INDIVIDUAL';
}
- /**
- * @param VObject\Property $attendee
- * @return string
- */
private function getPartstatOfAttendee(VObject\Property $attendee):string {
$partstat = $attendee->offsetGet('PARTSTAT');
if ($partstat instanceof VObject\Parameter) {
@@ -328,29 +302,25 @@ class EmailProvider extends AbstractProvider {
return 'NEEDS-ACTION';
}
- /**
- * @param VObject\Property $attendee
- * @return bool
- */
- private function hasAttendeeMailURI(VObject\Property $attendee):bool {
+ private function hasAttendeeMailURI(VObject\Property $attendee): bool {
return stripos($attendee->getValue(), 'mailto:') === 0;
}
- /**
- * @param VObject\Property $attendee
- * @return string|null
- */
- private function getEMailAddressOfAttendee(VObject\Property $attendee):?string {
+ private function getEMailAddressOfAttendee(VObject\Property $attendee): ?string {
if (!$this->hasAttendeeMailURI($attendee)) {
return null;
}
+ $attendeeEMail = substr($attendee->getValue(), 7);
+ if (!$this->mailer->validateMailAddress($attendeeEMail)) {
+ return null;
+ }
- return substr($attendee->getValue(), 7);
+ return $attendeeEMail;
}
/**
- * @param array $users
- * @return array
+ * @param IUser[] $users
+ * @return array<string, array{LANG?: string}>
*/
private function getEMailAddressesOfAllUsersWithWriteAccessToCalendar(array $users):array {
$emailAddresses = [];
@@ -373,12 +343,9 @@ class EmailProvider extends AbstractProvider {
}
/**
- * @param IL10N $l10n
- * @param VEvent $vevent
- * @return string
* @throws \Exception
*/
- private function generateDateString(IL10N $l10n, VEvent $vevent):string {
+ private function generateDateString(IL10N $l10n, VEvent $vevent): string {
$isAllDay = $vevent->DTSTART instanceof Property\ICalendar\Date;
/** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */
@@ -444,57 +411,27 @@ class EmailProvider extends AbstractProvider {
. ' (' . $startTimezone . ')';
}
- /**
- * @param DateTime $dtStart
- * @param DateTime $dtEnd
- * @return bool
- */
private function isDayEqual(DateTime $dtStart,
- DateTime $dtEnd):bool {
+ DateTime $dtEnd):bool {
return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d');
}
- /**
- * @param IL10N $l10n
- * @param DateTime $dt
- * @return string
- */
private function getWeekDayName(IL10N $l10n, DateTime $dt):string {
- return $l10n->l('weekdayName', $dt, ['width' => 'abbreviated']);
+ return (string)$l10n->l('weekdayName', $dt, ['width' => 'abbreviated']);
}
- /**
- * @param IL10N $l10n
- * @param DateTime $dt
- * @return string
- */
private function getDateString(IL10N $l10n, DateTime $dt):string {
- return $l10n->l('date', $dt, ['width' => 'medium']);
+ return (string)$l10n->l('date', $dt, ['width' => 'medium']);
}
- /**
- * @param IL10N $l10n
- * @param DateTime $dt
- * @return string
- */
private function getDateTimeString(IL10N $l10n, DateTime $dt):string {
- return $l10n->l('datetime', $dt, ['width' => 'medium|short']);
+ return (string)$l10n->l('datetime', $dt, ['width' => 'medium|short']);
}
- /**
- * @param IL10N $l10n
- * @param DateTime $dt
- * @return string
- */
private function getTimeString(IL10N $l10n, DateTime $dt):string {
- return $l10n->l('time', $dt, ['width' => 'short']);
+ return (string)$l10n->l('time', $dt, ['width' => 'short']);
}
- /**
- * @param VEvent $vevent
- * @param IL10N $l10n
- * @return string
- */
private function getTitleFromVEvent(VEvent $vevent, IL10N $l10n):string {
if (isset($vevent->SUMMARY)) {
return (string)$vevent->SUMMARY;
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/ProviderNotAvailableException.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/ProviderNotAvailableException.php
index 2e4f9a38493..15994bacf49 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/ProviderNotAvailableException.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/ProviderNotAvailableException.php
@@ -3,25 +3,8 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2018 Thomas Citharel <tcit@tcit.fr>
- *
- * @author Thomas Citharel <nextcloud@tcit.fr>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
diff --git a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php
index fb123960df8..a3f0cce547a 100644
--- a/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php
+++ b/apps/dav/lib/CalDAV/Reminder/NotificationProvider/PushProvider.php
@@ -3,41 +3,20 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2019, Thomas Citharel
- * @copyright Copyright (c) 2019, Georg Ehrke
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Georg Ehrke <oc.list@georgehrke.com>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Citharel <nextcloud@tcit.fr>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\CalDAV\Reminder\NotificationProvider;
use OCA\DAV\AppInfo\Application;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
-use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\L10N\IFactory as L10NFactory;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
+use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VEvent;
use Sabre\VObject\Property;
@@ -51,55 +30,44 @@ class PushProvider extends AbstractProvider {
/** @var string */
public const NOTIFICATION_TYPE = 'DISPLAY';
- /** @var IManager */
- private $manager;
-
- /** @var ITimeFactory */
- private $timeFactory;
-
- /**
- * @param IConfig $config
- * @param IManager $manager
- * @param ILogger $logger
- * @param L10NFactory $l10nFactory
- * @param IUrlGenerator $urlGenerator
- * @param ITimeFactory $timeFactory
- */
- public function __construct(IConfig $config,
- IManager $manager,
- ILogger $logger,
- L10NFactory $l10nFactory,
- IURLGenerator $urlGenerator,
- ITimeFactory $timeFactory) {
+ public function __construct(
+ IConfig $config,
+ private IManager $manager,
+ LoggerInterface $logger,
+ L10NFactory $l10nFactory,
+ IURLGenerator $urlGenerator,
+ private ITimeFactory $timeFactory,
+ ) {
parent::__construct($logger, $l10nFactory, $urlGenerator, $config);
- $this->manager = $manager;
- $this->timeFactory = $timeFactory;
}
/**
* Send push notification to all users.
*
* @param VEvent $vevent
- * @param string $calendarDisplayName
+ * @param string|null $calendarDisplayName
+ * @param string[] $principalEmailAddresses
* @param IUser[] $users
* @throws \Exception
*/
public function send(VEvent $vevent,
- string $calendarDisplayName = null,
- array $users = []):void {
- if ($this->config->getAppValue('dav', 'sendEventRemindersPush', 'no') !== 'yes') {
+ ?string $calendarDisplayName,
+ array $principalEmailAddresses,
+ array $users = []):void {
+ if ($this->config->getAppValue('dav', 'sendEventRemindersPush', 'yes') !== 'yes') {
return;
}
$eventDetails = $this->extractEventDetails($vevent);
- $eventDetails['calendar_displayname'] = $calendarDisplayName;
- $eventUUID = (string) $vevent->UID;
+ $eventUUID = (string)$vevent->UID;
if (!$eventUUID) {
return;
};
$eventUUIDHash = hash('sha256', $eventUUID, false);
foreach ($users as $user) {
+ $eventDetails['calendar_displayname'] = $calendarDisplayName ?? $this->getCalendarDisplayNameFallback($this->l10nFactory->getUserLanguage($user));
+
/** @var INotification $notification */
$notification = $this->manager->createNotification();
$notification->setApp(Application::APP_ID)
@@ -117,8 +85,6 @@ class PushProvider extends AbstractProvider {
}
/**
- * @var VEvent $vevent
- * @return array
* @throws \Exception
*/
protected function extractEventDetails(VEvent $vevent):array {
@@ -128,13 +94,13 @@ class PushProvider extends AbstractProvider {
return [
'title' => isset($vevent->SUMMARY)
- ? ((string) $vevent->SUMMARY)
+ ? ((string)$vevent->SUMMARY)
: null,
'description' => isset($vevent->DESCRIPTION)
- ? ((string) $vevent->DESCRIPTION)
+ ? ((string)$vevent->DESCRIPTION)
: null,
'location' => isset($vevent->LOCATION)
- ? ((string) $vevent->LOCATION)
+ ? ((string)$vevent->LOCATION)
: null,
'all_day' => $start instanceof Property\ICalendar\Date,
'start_atom' => $start->getDateTime()->format(\DateTimeInterface::ATOM),