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 <roeland@famdouma.nl>2020-05-15 16:56:11 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2020-07-07 21:37:49 +0300
commitc3a75055ff2aa51da6711f79452961c24c5ea933 (patch)
treeae4eb49fb64b99428f62fe832490ae6e565eba97
parentd8c79c71b60d1382adffbaebe538169d4e5e13cf (diff)
Add WebPushenh/support-push
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r--lib/App.php9
-rw-r--r--lib/AppInfo/Application.php2
-rw-r--r--lib/Push/WebPush.php46
-rw-r--r--lib/Push/WebPushContent.php40
-rw-r--r--lib/Push/WebPushValidator.php33
5 files changed, 128 insertions, 2 deletions
diff --git a/lib/App.php b/lib/App.php
index 4744bba..b67f1ab 100644
--- a/lib/App.php
+++ b/lib/App.php
@@ -21,8 +21,8 @@
namespace OCA\Notifications;
-
use OCA\Notifications\Exceptions\NotificationNotFoundException;
+use OCA\Notifications\Push\WebPush;
use OCP\Notification\IApp;
use OCP\Notification\INotification;
use Symfony\Component\Console\Output\OutputInterface;
@@ -32,10 +32,13 @@ class App implements IApp {
protected $handler;
/** @var Push */
protected $push;
+ /** @var WebPush */
+ protected $webPush;
- public function __construct(Handler $handler, Push $push) {
+ public function __construct(Handler $handler, Push $push, WebPush $webPush) {
$this->handler = $handler;
$this->push = $push;
+ $this->webPush = $webPush;
}
public function setOutput(OutputInterface $output): void {
@@ -53,6 +56,7 @@ class App implements IApp {
try {
$notificationToPush = $this->handler->getById($notificationId, $notification->getUser());
$this->push->pushToDevice($notificationId, $notificationToPush);
+ $this->webPush->pushNotify($notification->getUser());
} catch (NotificationNotFoundException $e) {
throw new \InvalidArgumentException('Error while preparing push notification');
}
@@ -77,6 +81,7 @@ class App implements IApp {
foreach ($deleted as $user => $notifications) {
foreach ($notifications as $notificationId) {
$this->push->pushDeleteToDevice($user, $notificationId);
+ $this->webPush->pushDelete($user);
}
}
}
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index caa6517..006e552 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -26,6 +26,7 @@ use OCA\Notifications\App;
use OCA\Notifications\Capabilities;
use OCA\Notifications\Listener\UserDeletedListener;
use OCA\Notifications\Notifier\AdminNotifications;
+use OCA\Notifications\Push\WebPushValidator;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
@@ -49,6 +50,7 @@ class Application extends \OCP\AppFramework\App implements IBootstrap {
});
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
+ $context->registerPushAccessValidator(WebPushValidator::class);
}
public function boot(IBootContext $context): void {
diff --git a/lib/Push/WebPush.php b/lib/Push/WebPush.php
new file mode 100644
index 0000000..52b1f41
--- /dev/null
+++ b/lib/Push/WebPush.php
@@ -0,0 +1,46 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Notifications\Push;
+
+use OCP\AppFramework\Services\IPush;
+
+class WebPush {
+
+ /** @var IPush */
+ private $push;
+
+ public function __construct(IPush $push) {
+ $this->push = $push;
+ }
+
+ public function pushNotify(string $uid) {
+ $this->push->publish($uid, new WebPushContent(['action' => 'add']));
+ }
+
+ public function pushDelete(string $uid) {
+ $this->push->publish($uid, new WebPushContent(['action' => 'delete']));
+ }
+}
diff --git a/lib/Push/WebPushContent.php b/lib/Push/WebPushContent.php
new file mode 100644
index 0000000..40fb19f
--- /dev/null
+++ b/lib/Push/WebPushContent.php
@@ -0,0 +1,40 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Notifications\Push;
+
+class WebPushContent implements \JsonSerializable {
+
+ /** @var array */
+ private $data;
+
+ public function __construct(array $data) {
+ $this->data = $data;
+ }
+
+ public function jsonSerialize() {
+ return $this->data;
+ }
+
+}
diff --git a/lib/Push/WebPushValidator.php b/lib/Push/WebPushValidator.php
new file mode 100644
index 0000000..0174b07
--- /dev/null
+++ b/lib/Push/WebPushValidator.php
@@ -0,0 +1,33 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Notifications\Push;
+
+use OCP\Push\IValidateAccess;
+
+class WebPushValidator implements IValidateAccess {
+ public function hasAccess(string $topic, string $uid): bool {
+ return $topic === $uid;
+ }
+}