summaryrefslogtreecommitdiffstats
path: root/apps/comments
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-04-30 14:29:30 +0200
committerJoas Schilling <coding@schilljs.com>2019-07-15 15:15:00 +0200
commit6d71e471e166c30c0b9abe05d36240b9f1556d8e (patch)
tree561fe5a415ddfc239f9b6e2549df55bfa6a7e51b /apps/comments
parent64f67818bcc6cc61cc49b1a7c032f3db85b73c91 (diff)
downloadnextcloud-server-6d71e471e166c30c0b9abe05d36240b9f1556d8e.tar.gz
nextcloud-server-6d71e471e166c30c0b9abe05d36240b9f1556d8e.zip
Update shipped implementations of the INotifier
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/comments')
-rw-r--r--apps/comments/lib/AppInfo/Application.php10
-rw-r--r--apps/comments/lib/Notification/Notifier.php27
2 files changed, 26 insertions, 11 deletions
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php
index b44c1c519c8..3d20cbbc169 100644
--- a/apps/comments/lib/AppInfo/Application.php
+++ b/apps/comments/lib/AppInfo/Application.php
@@ -76,15 +76,7 @@ class Application extends App {
}
protected function registerNotifier() {
- $this->getContainer()->getServer()->getNotificationManager()->registerNotifier(
- function() {
- return $this->getContainer()->query(Notifier::class);
- },
- function () {
- $l = $this->getContainer()->getServer()->getL10NFactory()->get('comments');
- return ['id' => 'comments', 'name' => $l->t('Comments')];
- }
- );
+ $this->getContainer()->getServer()->getNotificationManager()->registerNotifier(Notifier::class);
}
protected function registerCommentsEventHandler() {
diff --git a/apps/comments/lib/Notification/Notifier.php b/apps/comments/lib/Notification/Notifier.php
index 2132f05ef88..e8a7ade820d 100644
--- a/apps/comments/lib/Notification/Notifier.php
+++ b/apps/comments/lib/Notification/Notifier.php
@@ -32,6 +32,7 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\L10N\IFactory;
+use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\INotification;
use OCP\Notification\INotifier;
@@ -67,12 +68,34 @@ class Notifier implements INotifier {
}
/**
+ * Identifier of the notifier, only use [a-z0-9_]
+ *
+ * @return string
+ * @since 17.0.0
+ */
+ public function getID(): string {
+ return 'comments';
+ }
+
+ /**
+ * Human readable name describing the notifier
+ *
+ * @return string
+ * @since 17.0.0
+ */
+ public function getName(): string {
+ return $this->l10nFactory->get('comments')->t('Comments');
+ }
+
+ /**
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
* @throws \InvalidArgumentException When the notification was not prepared by a notifier
+ * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
+ * @since 9.0.0
*/
- public function prepare(INotification $notification, $languageCode) {
+ public function prepare(INotification $notification, string $languageCode): INotification {
if($notification->getApp() !== 'comments') {
throw new \InvalidArgumentException();
}
@@ -101,7 +124,7 @@ class Notifier implements INotifier {
$userFolder = $this->rootFolder->getUserFolder($notification->getUser());
$nodes = $userFolder->getById((int)$parameters[1]);
if(empty($nodes)) {
- throw new \InvalidArgumentException('Cannot resolve file ID to node instance');
+ throw new AlreadyProcessedException();
}
$node = $nodes[0];