From 352480981d867180d42af4f70cfc4c2d20e3d2e9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 16 Jul 2019 12:04:20 +0200 Subject: [PATCH 1/4] Adjust notifier to Nextcloud 17 Signed-off-by: Joas Schilling --- lib/AppInfo/Application.php | 10 +--------- lib/Notifier.php | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 14 deletions(-) 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/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'])) { From af0dd0a67877bb6e2cc64aebead4fd23b7657dc9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 4 Sep 2019 12:41:00 +0200 Subject: [PATCH 2/4] Require 17 only because of the notifier changes Signed-off-by: Joas Schilling --- appinfo/info.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 - + From 78263784fd847dc5d09fc84859b36541f0b456b5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 4 Sep 2019 12:41:31 +0200 Subject: [PATCH 3/4] Object id must be a string Signed-off-by: Joas Schilling --- lib/Backend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Backend.php b/lib/Backend.php index 2de1cdd..ddf5340 100644 --- a/lib/Backend.php +++ b/lib/Backend.php @@ -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', [ From 9e966060c40b875b3f523af6db8e5751f3f92e11 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 4 Sep 2019 12:41:59 +0200 Subject: [PATCH 4/4] Use short annotation Signed-off-by: Joas Schilling --- lib/Backend.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Backend.php b/lib/Backend.php index ddf5340..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();