diff --git a/appinfo/info.xml b/appinfo/info.xml index a7061dc..d4958bf 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -6,7 +6,7 @@ Receive a notification when an event in a shared calendar was added, modified or deleted. - 0.3.4 + 1.0.0 agpl Joas Schilling @@ -27,6 +27,6 @@ https://github.com/nickv-nextcloud/event_update_notification/raw/master/docs/demo.png - + diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 23b6e83..f277521 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -63,14 +63,6 @@ public function registerEventListener() { } protected function registerNotifier() { - $this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() { - return $this->getContainer()->query(Notifier::class); - }, function() { - $l = $this->getContainer()->getServer()->getL10NFactory()->get('event_update_notification'); - return [ - 'id' => 'event_update_notification', - 'name' => $l->t('Calendar event update notifications'), - ]; - }); + $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class); } } diff --git a/lib/Backend.php b/lib/Backend.php index 2de1cdd..77528ae 100644 --- a/lib/Backend.php +++ b/lib/Backend.php @@ -83,7 +83,7 @@ public function onTouchCalendarObject(string $action, array $calendarData, array } $classification = $objectData['classification'] ?? CalDavBackend::CLASSIFICATION_PUBLIC; - $action = $action . '_' . $object['type']; + $action .= '_' . $object['type']; list ($dateTime, $hasTime) = $this->getNearestDateTime($objectData['calendardata']); $now = new \DateTime(); @@ -94,7 +94,7 @@ public function onTouchCalendarObject(string $action, array $calendarData, array $notification = $this->notificationManager->createNotification(); $notification->setApp('event_update_notification') - ->setObject('calendar', (int) $calendarData['id']) + ->setObject('calendar', (string) $calendarData['id']) ->setUser($currentUser) ->setDateTime($now) ->setMessage('event_update_notification', [ diff --git a/lib/Notifier.php b/lib/Notifier.php index 8dcb492..205d1af 100644 --- a/lib/Notifier.php +++ b/lib/Notifier.php @@ -32,6 +32,7 @@ use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; +use OCP\Notification\AlreadyProcessedException; use OCP\Notification\IManager as INotificationManager; use OCP\Notification\INotification; use OCP\Notification\INotifier; @@ -74,6 +75,26 @@ public function __construct(IFactory $languageFactory, $this->dateTimeFormatter = $dateTimeFormatter; } + /** + * Identifier of the notifier, only use [a-z0-9_] + * + * @return string + * @since 17.0.0 + */ + public function getID(): string { + return 'event_update_notification'; + } + + /** + * Human readable name describing the notifier + * + * @return string + * @since 17.0.0 + */ + public function getName(): string { + return $this->languageFactory->get('event_update_notification')->t('Calendar event update notifications'); + } + /** * @param INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification @@ -81,7 +102,7 @@ public function __construct(IFactory $languageFactory, * @throws \InvalidArgumentException When the notification was not prepared by a notifier * @since 9.0.0 */ - public function prepare(INotification $notification, $languageCode): INotification { + public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== 'event_update_notification') { throw new \InvalidArgumentException('Invalid app'); } @@ -97,16 +118,14 @@ public function prepare(INotification $notification, $languageCode): INotificati } else if ($notification->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event') { $subject = $this->l->t('{actor} updated {event} in {calendar}'); } else { - $this->notificationManager->markProcessed($notification); - throw new \InvalidArgumentException('Invalid subject'); + throw new AlreadyProcessedException(); } $params = $notification->getMessageParameters(); $start = \DateTime::createFromFormat(\DateTime::ATOM, $params['start']); if ($start < $this->timeFactory->getDateTime()) { - $this->notificationManager->markProcessed($notification); - throw new \InvalidArgumentException('Past event'); + throw new AlreadyProcessedException(); } if (!empty($params['hasTime'])) {