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
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-12-11 14:49:23 +0300
committerGitHub <noreply@github.com>2019-12-11 14:49:23 +0300
commit423eec41c75b0bae8edf0c745f4e8582c6493cad (patch)
treed78210fad64172af8586cb681a8960f58e288233
parent065507974964d4ec6790737b648e8569a6faebe0 (diff)
parent36b64ec1c5a94a0011c07a35fc8aa7269400269d (diff)
Merge pull request #508 from nextcloud/enh/dismissv18.0.0beta2
Dismiss notifications properly
-rw-r--r--lib/Controller/EndpointController.php11
-rw-r--r--lib/Handler.php20
-rw-r--r--tests/Unit/HandlerTest.php2
3 files changed, 24 insertions, 9 deletions
diff --git a/lib/Controller/EndpointController.php b/lib/Controller/EndpointController.php
index 1cde7ef..167b5bb 100644
--- a/lib/Controller/EndpointController.php
+++ b/lib/Controller/EndpointController.php
@@ -164,10 +164,15 @@ class EndpointController extends OCSController {
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}
- $deleted = $this->handler->deleteById($id, $this->getCurrentUser());
- if ($deleted) {
- $this->push->pushDeleteToDevice($this->getCurrentUser(), $id);
+ try {
+ $deleted = $this->handler->deleteById($id, $this->getCurrentUser());
+
+ if ($deleted) {
+ $this->push->pushDeleteToDevice($this->getCurrentUser(), $id);
+ }
+ } catch (NotificationNotFoundException $e) {
}
+
return new DataResponse();
}
diff --git a/lib/Handler.php b/lib/Handler.php
index 864f435..f1f3db1 100644
--- a/lib/Handler.php
+++ b/lib/Handler.php
@@ -88,25 +88,27 @@ class Handler {
*/
public function delete(INotification $notification): array {
$sql = $this->connection->getQueryBuilder();
- $sql->select('notification_id', 'user')
+ $sql->select('*')
->from('notifications');
$this->sqlWhere($sql, $notification);
$statement = $sql->execute();
$deleted = [];
+ $notifications = [];
while ($row = $statement->fetch()) {
if (!isset($deleted[$row['user']])) {
$deleted[$row['user']] = [];
}
$deleted[$row['user']][] = (int) $row['notification_id'];
+ $notifications[(int) $row['notification_id']] = $this->notificationFromRow($row);
}
$statement->closeCursor();
- foreach ($deleted as $user => $notifications) {
- foreach ($notifications as $notificationId) {
- $this->deleteById($notificationId, $user);
+ foreach ($deleted as $user => $notificationIds) {
+ foreach ($notificationIds as $notificationId) {
+ $this->deleteById($notificationId, $user, $notifications[$notificationId]);
}
}
@@ -134,9 +136,17 @@ class Handler {
*
* @param int $id
* @param string $user
+ * @param INotification|null $notification
* @return bool
+ * @throws NotificationNotFoundException
*/
- public function deleteById(int $id, string $user): bool {
+ public function deleteById(int $id, string $user, ?INotification $notification = null): bool {
+ if (!$notification instanceof INotification) {
+ $notification = $this->getById($id, $user);
+ }
+
+ $this->manager->dismissNotification($notification);
+
$sql = $this->connection->getQueryBuilder();
$sql->delete('notifications')
->where($sql->expr()->eq('notification_id', $sql->createNamedParameter($id)))
diff --git a/tests/Unit/HandlerTest.php b/tests/Unit/HandlerTest.php
index f56b2cf..0914b6a 100644
--- a/tests/Unit/HandlerTest.php
+++ b/tests/Unit/HandlerTest.php
@@ -158,7 +158,7 @@ class HandlerTest extends TestCase {
}
// Delete with wrong user
- $this->handler->deleteById($notificationId, 'test_user2');
+ $this->handler->deleteById($notificationId, 'test_user2', $notification);
$this->assertSame(1, $this->handler->count($limitedNotification), 'Wrong notification count for user1 after trying to delete for user2');
// Get with correct user