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

github.com/nextcloud/notifications.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-01-29 18:53:55 +0300
committerJoas Schilling <coding@schilljs.com>2018-02-02 16:01:51 +0300
commit5ce598d4203f9a55d6fed1c9cb930b595b4225bb (patch)
treec25d9d29937cfa5cbe08fe4784ab99147a63bb99 /lib
parent508c1f6853ed30484227f4b4a1bc0134726d1cb8 (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.php1
-rw-r--r--lib/Controller/EndpointController.php10
-rw-r--r--lib/Handler.php15
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