diff options
author | Joas Schilling <coding@schilljs.com> | 2019-02-28 21:58:24 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-02-28 21:58:24 +0300 |
commit | 2f3e0a8409958be5ca64c1b6b0d49e4bdc0206b1 (patch) | |
tree | 5ef22c96b086afb16920611464f51ab9b14f7839 | |
parent | eaa64559f5be3ed98f32cb69eb132d6504f4e9d5 (diff) |
Automatically remove notifications for past events
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/Notifier.php | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/Notifier.php b/lib/Notifier.php index ece3d08..8dcb492 100644 --- a/lib/Notifier.php +++ b/lib/Notifier.php @@ -25,12 +25,14 @@ declare(strict_types=1); namespace OCA\EventUpdateNotification; use OCA\DAV\CalDAV\CalDavBackend; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\IDateTimeFormatter; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\L10N\IFactory; +use OCP\Notification\IManager as INotificationManager; use OCP\Notification\INotification; use OCP\Notification\INotifier; @@ -42,26 +44,33 @@ class Notifier implements INotifier { /** @var IFactory */ protected $languageFactory; - + /** @var ITimeFactory */ + protected $timeFactory; /** @var IL10N */ protected $l; - /** @var IURLGenerator */ protected $url; - /** @var IUserManager */ protected $userManager; - + /** @var INotificationManager */ + protected $notificationManager; /** @var IDateTimeFormatter */ protected $dateTimeFormatter; /** @var string[] */ protected $userDisplayNames = []; - public function __construct(IFactory $languageFactory, IURLGenerator $url, IUserManager $userManager, IDateTimeFormatter $dateTimeFormatter) { + public function __construct(IFactory $languageFactory, + ITimeFactory $timeFactory, + IURLGenerator $url, + IUserManager $userManager, + INotificationManager $notificationManager, + IDateTimeFormatter $dateTimeFormatter) { $this->languageFactory = $languageFactory; + $this->timeFactory = $timeFactory; $this->url = $url; $this->userManager = $userManager; + $this->notificationManager = $notificationManager; $this->dateTimeFormatter = $dateTimeFormatter; } @@ -88,11 +97,18 @@ class Notifier implements INotifier { } else if ($notification->getSubject() === self::SUBJECT_OBJECT_UPDATE . '_event') { $subject = $this->l->t('{actor} updated {event} in {calendar}'); } else { + $this->notificationManager->markProcessed($notification); throw new \InvalidArgumentException('Invalid subject'); } $params = $notification->getMessageParameters(); $start = \DateTime::createFromFormat(\DateTime::ATOM, $params['start']); + + if ($start < $this->timeFactory->getDateTime()) { + $this->notificationManager->markProcessed($notification); + throw new \InvalidArgumentException('Past event'); + } + if (!empty($params['hasTime'])) { $notification->setParsedMessage( $this->dateTimeFormatter->formatDateTime( |