From 674a33a066686b7ce51d9ddd1913c15859490098 Mon Sep 17 00:00:00 2001 From: dartcafe Date: Sat, 6 Mar 2021 16:59:54 +0100 Subject: remove notification, if poll not found #1421 Signed-off-by: dartcafe --- lib/Notification/Notifier.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 6738d26a..60c6dfb8 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -24,33 +24,45 @@ namespace OCA\Polls\Notification; +use OCP\AppFramework\Db\DoesNotExistException; + use OCP\IURLGenerator; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\Notification\INotification; use OCP\Notification\INotifier; use OCA\Polls\Db\PollMapper; +use OCA\Polls\Service\NotificationService; class Notifier implements INotifier { + /** @var IFactory */ protected $l10nFactory; + /** @var IURLGenerator */ protected $url; + /** @var IUserManager */ protected $userManager; + /** @var PollMapper */ protected $pollMapper; + /** @var NotificationService */ + private $notificationService; + public function __construct( IFactory $l10nFactory, IURLGenerator $url, IUserManager $userManager, - PollMapper $pollMapper + PollMapper $pollMapper, + NotificationService $notificationService ) { $this->l10nFactory = $l10nFactory; $this->url = $url; $this->userManager = $userManager; $this->pollMapper = $pollMapper; + $this->notificationService = $notificationService; } /** @@ -72,12 +84,20 @@ class Notifier implements INotifier { if ($notification->getApp() !== 'polls') { throw new \InvalidArgumentException(); } + + try { + $poll = $this->pollMapper->find(intval($notification->getObjectId())); + } catch (DoesNotExistException $e) { + $this->notificationService->removeNotification(intval($notification->getObjectId())); + throw new \InvalidArgumentException(); + } + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('polls', 'polls-black.svg'))); $parameters = $notification->getSubjectParameters(); switch ($notification->getSubject()) { case 'invitation': - $poll = $this->pollMapper->find(intval($notification->getObjectId())); + $owner = $this->userManager->get($poll->getOwner()); $notification->setParsedSubject( @@ -101,7 +121,6 @@ class Notifier implements INotifier { break; case 'takeOverPoll': - $poll = $this->pollMapper->find(intval($notification->getObjectId())); $newOwner = $this->userManager->get($parameters['actor']); $notification->setParsedSubject( @@ -125,7 +144,6 @@ class Notifier implements INotifier { break; case 'deletePollByOther': - $poll = $this->pollMapper->find(intval($notification->getObjectId())); $actor = $this->userManager->get($parameters['actor']); $notification->setParsedSubject( @@ -149,7 +167,6 @@ class Notifier implements INotifier { break; case 'softDeletePollByOther': - $poll = $this->pollMapper->find(intval($notification->getObjectId())); $actor = $this->userManager->get($parameters['actor']); $notification->setParsedSubject( -- cgit v1.2.3