From aefd7bd3b089583dfb10914f46bb8141d3742c76 Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Mon, 30 Sep 2019 23:22:59 +0100 Subject: [PATCH] Adjust notifier registration for Nextcloud 17 API. This patch implements the changes recommended in issue #610 following the overhaul of the notification API introduced in Nextcloud 17: * Update the signature of the INotifier::prepare method. * Use the new NotificationManager::registerNotifierService method instead of NotificationManager::registerNotifier (deprecated). Signed-off-by: Damien Goutte-Gattat --- appinfo/app.php | 13 +------------ lib/Notifier.php | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/appinfo/app.php b/appinfo/app.php index cee29ffe..46519247 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -23,19 +23,8 @@ $app = new \OCA\Passman\AppInfo\Application(); $app->registerNavigationEntry(); $app->registerPersonalPage(); - -$l = \OC::$server->getL10N('passman'); $manager = \OC::$server->getNotificationManager(); -$manager->registerNotifier(function() { - return new Notifier( - \OC::$server->getL10NFactory() - ); -}, function() use ($l) { - return [ - 'id' => 'passman', - 'name' => $l->t('Passwords'), - ]; -}); +$manager->registerNotifierService(Notifier::class); /** * Loading translations diff --git a/lib/Notifier.php b/lib/Notifier.php index fcf7e45a..3282fc4c 100644 --- a/lib/Notifier.php +++ b/lib/Notifier.php @@ -37,7 +37,7 @@ class Notifier implements INotifier { * @param INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification */ - public function prepare(INotification $notification, $languageCode) { + public function prepare(INotification $notification, string $languageCode): INotification { if ($notification->getApp() !== 'passman') { // Not my app => throw throw new \InvalidArgumentException(); @@ -109,4 +109,22 @@ class Notifier implements INotifier { throw new \InvalidArgumentException(); } } -} \ No newline at end of file + + /** + * Identifier of the notifier + * + * @return string + */ + public function getID(): string { + return 'passman'; + } + + /** + * Human readable name describing the notifier + * + * @return string + */ + public function getName(): string { + return $this->factory->get('passman')->t('Passwords'); + } +}