diff options
author | Joas Schilling <coding@schilljs.com> | 2018-01-29 18:53:55 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2018-02-02 16:01:51 +0300 |
commit | 5ce598d4203f9a55d6fed1c9cb930b595b4225bb (patch) | |
tree | c25d9d29937cfa5cbe08fe4784ab99147a63bb99 /lib | |
parent | 508c1f6853ed30484227f4b4a1bc0134726d1cb8 (diff) |
Add an endpoint to delete all notifications
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Capabilities.php | 1 | ||||
-rw-r--r-- | lib/Controller/EndpointController.php | 10 | ||||
-rw-r--r-- | lib/Handler.php | 15 |
3 files changed, 26 insertions, 0 deletions
diff --git a/lib/Capabilities.php b/lib/Capabilities.php index 6b832f6..0c0fd3f 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -42,6 +42,7 @@ class Capabilities implements ICapability { 'list', 'get', 'delete', + 'delete-all', 'icons', 'rich-strings', ], diff --git a/lib/Controller/EndpointController.php b/lib/Controller/EndpointController.php index 3c430a7..f84b6d5 100644 --- a/lib/Controller/EndpointController.php +++ b/lib/Controller/EndpointController.php @@ -158,6 +158,16 @@ class EndpointController extends OCSController { } /** + * @NoAdminRequired + * + * @return DataResponse + */ + public function deleteAllNotifications(): DataResponse { + $this->handler->deleteByUser($this->getCurrentUser()); + return new DataResponse(); + } + + /** * Get an Etag for the notification ids * * @param array $notifications diff --git a/lib/Handler.php b/lib/Handler.php index cba6e13..d9fa2c5 100644 --- a/lib/Handler.php +++ b/lib/Handler.php @@ -92,6 +92,21 @@ class Handler { } /** + * Delete the notification of a given user + * + * @param string $user + */ + public function deleteByUser(string $user) { + $notification = $this->manager->createNotification(); + try { + $notification->setUser($user); + } catch (\InvalidArgumentException $e) { + return; + } + $this->delete($notification); + } + + /** * Delete the notification matching the given id * * @param int $id |