diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 8d261f3495..563d7cf7c7 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -367,6 +367,7 @@ return array( 'OCP\\Notification\\AlreadyProcessedException' => $baseDir . '/lib/public/Notification/AlreadyProcessedException.php', 'OCP\\Notification\\IAction' => $baseDir . '/lib/public/Notification/IAction.php', 'OCP\\Notification\\IApp' => $baseDir . '/lib/public/Notification/IApp.php', + 'OCP\\Notification\\IDismissableNotifier' => $baseDir . '/lib/public/Notification/IDismissableNotifier.php', 'OCP\\Notification\\IManager' => $baseDir . '/lib/public/Notification/IManager.php', 'OCP\\Notification\\INotification' => $baseDir . '/lib/public/Notification/INotification.php', 'OCP\\Notification\\INotifier' => $baseDir . '/lib/public/Notification/INotifier.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 806a36e3c6..140ec46185 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -396,6 +396,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Notification\\AlreadyProcessedException' => __DIR__ . '/../../..' . '/lib/public/Notification/AlreadyProcessedException.php', 'OCP\\Notification\\IAction' => __DIR__ . '/../../..' . '/lib/public/Notification/IAction.php', 'OCP\\Notification\\IApp' => __DIR__ . '/../../..' . '/lib/public/Notification/IApp.php', + 'OCP\\Notification\\IDismissableNotifier' => __DIR__ . '/../../..' . '/lib/public/Notification/IDismissableNotifier.php', 'OCP\\Notification\\IManager' => __DIR__ . '/../../..' . '/lib/public/Notification/IManager.php', 'OCP\\Notification\\INotification' => __DIR__ . '/../../..' . '/lib/public/Notification/INotification.php', 'OCP\\Notification\\INotifier' => __DIR__ . '/../../..' . '/lib/public/Notification/INotifier.php', diff --git a/lib/private/Notification/Manager.php b/lib/private/Notification/Manager.php index 5d640c66be..7791258d41 100644 --- a/lib/private/Notification/Manager.php +++ b/lib/private/Notification/Manager.php @@ -31,6 +31,7 @@ use OCP\AppFramework\QueryException; use OCP\ILogger; use OCP\Notification\AlreadyProcessedException; use OCP\Notification\IApp; +use OCP\Notification\IDismissableNotifier; use OCP\Notification\IManager; use OCP\Notification\INotification; use OCP\Notification\INotifier; @@ -296,4 +297,18 @@ class Manager implements IManager { return $count; } + + public function dismissNotification(INotification $notification): void { + $notifiers = $this->getNotifiers(); + + foreach ($notifiers as $notifier) { + if ($notifier instanceof IDismissableNotifier) { + try { + $notifier->dismissNotification($notification); + } catch (\InvalidArgumentException $e) { + continue; + } + } + } + } } diff --git a/lib/public/Notification/IDismissableNotifier.php b/lib/public/Notification/IDismissableNotifier.php new file mode 100644 index 0000000000..61088fc72e --- /dev/null +++ b/lib/public/Notification/IDismissableNotifier.php @@ -0,0 +1,45 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\Notification; + +/** + * Interface INotifier classes should implement if they want to process notifications + * that are dismissed by the user. + * + * This can be useful if dismissing the notification will leave it in an incomplete + * state. The handler can chose to for example do some default action. + * + * @since 18.0.0 + */ +interface IDismissableNotifier extends INotifier { + + /** + * @param INotification $notification + * @throws \InvalidArgumentException In case the handler can't handle the notification + * + * @since 18.0.0 + */ + public function dismissNotification(INotification $notification): void; +} diff --git a/lib/public/Notification/IManager.php b/lib/public/Notification/IManager.php index c1c4d88161..2a9b8116a5 100644 --- a/lib/public/Notification/IManager.php +++ b/lib/public/Notification/IManager.php @@ -85,4 +85,9 @@ interface IManager extends IApp, INotifier { * @since 14.0.0 */ public function isPreparingPushNotification(): bool; + + /** + * @since 18.0.0 + */ + public function dismissNotification(INotification $notification): void; }