diff options
Diffstat (limited to 'apps/comments')
5 files changed, 42 insertions, 12 deletions
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php index b44c1c519c8..916345e4a5f 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()->registerNotifierService(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]; diff --git a/apps/comments/tests/Unit/Controller/NotificationsTest.php b/apps/comments/tests/Unit/Controller/NotificationsTest.php index c5209b9f9d5..9df81f01b02 100644 --- a/apps/comments/tests/Unit/Controller/NotificationsTest.php +++ b/apps/comments/tests/Unit/Controller/NotificationsTest.php @@ -117,6 +117,9 @@ class NotificationsTest extends TestCase { $comment->expects($this->any()) ->method('getObjectType') ->willReturn('files'); + $comment->expects($this->any()) + ->method('getId') + ->willReturn('1234'); $this->commentsManager->expects($this->any()) ->method('get') @@ -192,6 +195,9 @@ class NotificationsTest extends TestCase { $comment->expects($this->any()) ->method('getObjectType') ->willReturn('files'); + $comment->expects($this->any()) + ->method('getId') + ->willReturn('1234'); $this->commentsManager->expects($this->any()) ->method('get') diff --git a/apps/comments/tests/Unit/Notification/ListenerTest.php b/apps/comments/tests/Unit/Notification/ListenerTest.php index d6f83262f30..e31b227bce8 100644 --- a/apps/comments/tests/Unit/Notification/ListenerTest.php +++ b/apps/comments/tests/Unit/Notification/ListenerTest.php @@ -91,6 +91,9 @@ class ListenerTest extends TestCase { [ 'type' => 'user', 'id' => '23452-4333-54353-2342'], [ 'type' => 'user', 'id' => 'yolo'], ]); + $comment->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn('1234'); /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder(CommentsEvent::class) @@ -186,6 +189,9 @@ class ListenerTest extends TestCase { $comment->expects($this->once()) ->method('getMentions') ->willReturn([[ 'type' => 'user', 'id' => 'foobar']]); + $comment->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn('1234'); /** @var CommentsEvent|\PHPUnit_Framework_MockObject_MockObject $event */ $event = $this->getMockBuilder(CommentsEvent::class) diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php index 6eceed44919..d008c4c3121 100644 --- a/apps/comments/tests/Unit/Notification/NotifierTest.php +++ b/apps/comments/tests/Unit/Notification/NotifierTest.php @@ -195,6 +195,9 @@ class NotifierTest extends TestCase { ->expects($this->any()) ->method('getMentions') ->willReturn([['type' => 'user', 'id' => 'you']]); + $this->comment->expects($this->atLeastOnce()) + ->method('getId') + ->willReturn('1234'); $this->commentsManager ->expects($this->once()) @@ -539,7 +542,7 @@ class NotifierTest extends TestCase { } /** - * @expectedException \InvalidArgumentException + * @expectedException \OCP\Notification\AlreadyProcessedException */ public function testPrepareUnresolvableFileID() { $displayName = 'Huraga'; |