diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2019-12-09 13:54:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-09 13:54:32 +0300 |
commit | 9f978be45e2242bf63b9ef2fb197c86eed24c333 (patch) | |
tree | 7bf344e1ec5cd5774cd9d2f189ec749a488e75c8 | |
parent | 7b909fd97b7c48157a5bacedd345c03c6da25446 (diff) | |
parent | a72fb72d80197165e71d7ad917b19b928f251ce0 (diff) |
Merge pull request #506 from nextcloud/backport/505/stable17v17.0.2RC1
[stable17] Do not send push notifications when nothing was deleted
-rw-r--r-- | lib/Controller/EndpointController.php | 12 | ||||
-rw-r--r-- | lib/Handler.php | 12 |
2 files changed, 15 insertions, 9 deletions
diff --git a/lib/Controller/EndpointController.php b/lib/Controller/EndpointController.php index 97c657a..1cde7ef 100644 --- a/lib/Controller/EndpointController.php +++ b/lib/Controller/EndpointController.php @@ -164,8 +164,10 @@ class EndpointController extends OCSController { return new DataResponse(null, Http::STATUS_NOT_FOUND); } - $this->handler->deleteById($id, $this->getCurrentUser()); - $this->push->pushDeleteToDevice($this->getCurrentUser(), $id); + $deleted = $this->handler->deleteById($id, $this->getCurrentUser()); + if ($deleted) { + $this->push->pushDeleteToDevice($this->getCurrentUser(), $id); + } return new DataResponse(); } @@ -175,8 +177,10 @@ class EndpointController extends OCSController { * @return DataResponse */ public function deleteAllNotifications(): DataResponse { - $this->handler->deleteByUser($this->getCurrentUser()); - $this->push->pushDeleteToDevice($this->getCurrentUser(), 0); + $deletedSomething = $this->handler->deleteByUser($this->getCurrentUser()); + if ($deletedSomething) { + $this->push->pushDeleteToDevice($this->getCurrentUser(), 0); + } return new DataResponse(); } diff --git a/lib/Handler.php b/lib/Handler.php index d8c2451..864f435 100644 --- a/lib/Handler.php +++ b/lib/Handler.php @@ -117,15 +117,16 @@ class Handler { * Delete the notification of a given user * * @param string $user + * @return bool */ - public function deleteByUser(string $user) { + public function deleteByUser(string $user): bool { $notification = $this->manager->createNotification(); try { $notification->setUser($user); } catch (\InvalidArgumentException $e) { - return; + return false; } - $this->delete($notification); + return !empty($this->delete($notification)); } /** @@ -133,13 +134,14 @@ class Handler { * * @param int $id * @param string $user + * @return bool */ - public function deleteById(int $id, string $user) { + public function deleteById(int $id, string $user): bool { $sql = $this->connection->getQueryBuilder(); $sql->delete('notifications') ->where($sql->expr()->eq('notification_id', $sql->createNamedParameter($id))) ->andWhere($sql->expr()->eq('user', $sql->createNamedParameter($user))); - $sql->execute(); + return (bool) $sql->execute(); } /** |