Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2021-03-06 18:59:54 +0300
committerdartcafe <github@dartcafe.de>2021-03-06 18:59:54 +0300
commit674a33a066686b7ce51d9ddd1913c15859490098 (patch)
treefc66385522b73c164dd4d06ba5f9bd78f5466286 /lib
parent58b59eb79229898f23c7637a2c0f32de2745688f (diff)
remove notification, if poll not found #1421
Signed-off-by: dartcafe <github@dartcafe.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Notification/Notifier.php27
1 files changed, 22 insertions, 5 deletions
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(