Skip to content

Commit

Permalink
Adjust notifier registration for Nextcloud 17 API.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
gouttegd committed Oct 1, 2019
1 parent 27cbb82 commit aefd7bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
13 changes: 1 addition & 12 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,8 @@
$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
Expand Down
22 changes: 20 additions & 2 deletions lib/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(\OCP\L10N\IFactory $factory) {
* @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();
Expand Down Expand Up @@ -109,4 +109,22 @@ public function prepare(INotification $notification, $languageCode) {
throw new \InvalidArgumentException();
}
}
}

/**
* 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');
}
}

0 comments on commit aefd7bd

Please sign in to comment.