From b0335735fed3ae0cbe5f43c7a75afdc4882e59b4 Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Mon, 17 Jun 2024 15:23:21 +0200 Subject: [PATCH] implemented draft spec of web push transport --- lib/PushTransports/WebPushTransport.php | 41 ++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/lib/PushTransports/WebPushTransport.php b/lib/PushTransports/WebPushTransport.php index 0eaa3f3..d15cbb6 100644 --- a/lib/PushTransports/WebPushTransport.php +++ b/lib/PushTransports/WebPushTransport.php @@ -27,18 +27,49 @@ declare(strict_types=1); namespace OCA\DavPush\PushTransports; use OCA\DavPush\Transport\Transport; +use Sabre\Xml\Service; class WebPushTransport extends Transport { protected $id = "web-push"; public function registerSubscription($options) { - return [ - 'success' => True, - 'response' => "web push test", - ]; + $pushResource = False; + + foreach($options as $option) { + if ($option["name"] == "{DAV:Push}push-resource") { + $pushResource = $option["value"]; + } + } + + if($pushResource) { + return [ + 'success' => True, + 'response' => "", + 'data' => [ "pushResource" => $pushResource ], + ]; + } else { + return [ + 'success' => False, + 'error' => "push resource not provided", + ]; + } } public function notify(string $userId, string $collectionName, $data) { + $xmlService = new Service(); + $content = $xmlService->write('{DAV:Push}push-message', [ + 'topic' => $collectionName, + ]); + + $options = [ + 'http' => [ + 'method' => 'POST', + 'content' => $content, + ], + ]; + + $context = stream_context_create($options); + $result = file_get_contents($data["pushResource"], false, $context); } -} \ No newline at end of file +}