diff --git a/lib/private/Notification/Manager.php b/lib/private/Notification/Manager.php index 0e945ccf09f9..c74264f264cf 100644 --- a/lib/private/Notification/Manager.php +++ b/lib/private/Notification/Manager.php @@ -22,6 +22,7 @@ namespace OC\Notification; +use OCP\IUser; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use OCP\Notification\IApp; use OCP\Notification\IManager; @@ -32,6 +33,7 @@ use OCP\Notification\Events\RegisterNotifierEvent; use OC\Notification\Events\RegisterConsumerEventImpl; use OC\Notification\Events\RegisterNotifierEventImpl; +use Symfony\Component\EventDispatcher\GenericEvent; class Manager implements IManager { /** @var EventDispatcherInterface */ @@ -72,6 +74,10 @@ public function __construct(EventDispatcherInterface $dispatcher) { $this->notifiersInfoClosures = []; $this->builtAppsHolder = []; + + $this->dispatcher->addListener('user.afterdelete', function (GenericEvent $event) { + $this->removeUserNotifications($event->getArgument('uid')); + }); } /** @@ -299,4 +305,12 @@ public function getCount(INotification $notification) { return $count; } + + public function removeUserNotifications($uid) { + $apps = $this->getApps(); + + foreach ($apps as $app) { + $app->removeUserNotifications($uid); + } + } } diff --git a/lib/public/Notification/IApp.php b/lib/public/Notification/IApp.php index 75cc7f170b4f..3d1bb31e4b35 100644 --- a/lib/public/Notification/IApp.php +++ b/lib/public/Notification/IApp.php @@ -49,4 +49,11 @@ public function markProcessed(INotification $notification); * @since 9.0.0 */ public function getCount(INotification $notification); + + /** + * @param $uid + * @return null + * @since 10.1.0 + */ + public function removeUserNotifications($uid); } diff --git a/tests/lib/Notification/ManagerTest.php b/tests/lib/Notification/ManagerTest.php index 03a912c463a7..4ff1446b25f0 100644 --- a/tests/lib/Notification/ManagerTest.php +++ b/tests/lib/Notification/ManagerTest.php @@ -645,4 +645,17 @@ public function testGetCount() { $this->assertSame(63, $this->manager->getCount($notification)); } + + public function testRemoveUserNotifications() { + $app = $this->createMock(IApp::class); + $app->expects($this->once()) + ->method('removeUserNotifications') + ->with('foo'); + + $this->manager->registerApp(function () use ($app) { + return $app; + }); + + $this->manager->removeUserNotifications('foo'); + } }