adapt web push transport to transport provider api changes
This commit is contained in:
parent
bc55f3bed5
commit
71ecda7b63
1 changed files with 42 additions and 9 deletions
|
@ -27,34 +27,57 @@ declare(strict_types=1);
|
||||||
namespace OCA\DavPush\PushTransports;
|
namespace OCA\DavPush\PushTransports;
|
||||||
|
|
||||||
use OCA\DavPush\Transport\Transport;
|
use OCA\DavPush\Transport\Transport;
|
||||||
|
use OCA\DavPush\Service\WebPushSubscriptionService;
|
||||||
|
|
||||||
use Sabre\Xml\Service;
|
use Sabre\Xml\Service;
|
||||||
|
|
||||||
class WebPushTransport extends Transport {
|
class WebPushTransport extends Transport {
|
||||||
protected $id = "web-push";
|
protected $id = "web-push";
|
||||||
|
|
||||||
public function registerSubscription($options) {
|
public function __construct(
|
||||||
$pushResource = False;
|
private WebPushSubscriptionService $webPushSubscriptionService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
private function parseOptions(array $options): array {
|
||||||
|
$result = [];
|
||||||
|
|
||||||
foreach($options as $option) {
|
foreach($options as $option) {
|
||||||
if ($option["name"] == "{DAV:Push}push-resource") {
|
if ($option["name"] == "{DAV:Push}push-resource") {
|
||||||
$pushResource = $option["value"];
|
$result["pushResource"] = $option["value"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($pushResource) {
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function validateOptions($options): array {
|
||||||
|
['pushResource' => $pushResource] = $this->parseOptions($options);
|
||||||
|
|
||||||
|
// TODO: check if string is valid URL
|
||||||
|
|
||||||
|
if(isset($pushResource) && $pushResource !== '') {
|
||||||
return [
|
return [
|
||||||
'success' => True,
|
'valid' => True,
|
||||||
'response' => "",
|
|
||||||
'data' => [ "pushResource" => $pushResource ],
|
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return [
|
return [
|
||||||
'success' => False,
|
'valid' => False,
|
||||||
'error' => "push resource not provided",
|
'errors' => ["push resource not provided"]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function registerSubscription($subsciptionId, $options) {
|
||||||
|
['pushResource' => $pushResource] = $this->parseOptions($options);
|
||||||
|
|
||||||
|
$this->webPushSubscriptionService->create($subsciptionId, $pushResource);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'success' => True,
|
||||||
|
'response' => "",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function notify(string $userId, string $collectionName, $data) {
|
public function notify(string $userId, string $collectionName, $data) {
|
||||||
$xmlService = new Service();
|
$xmlService = new Service();
|
||||||
|
|
||||||
|
@ -72,4 +95,14 @@ class WebPushTransport extends Transport {
|
||||||
$context = stream_context_create($options);
|
$context = stream_context_create($options);
|
||||||
$result = file_get_contents($data["pushResource"], false, $context);
|
$result = file_get_contents($data["pushResource"], false, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSubscriptionIdFromOptions($options): int {
|
||||||
|
['pushResource' => $pushResource] = $this->parseOptions($options);
|
||||||
|
|
||||||
|
return $this->webPushSubscriptionService->findByPushResource($pushResource)->getSubscriptionId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateSubscription($subsciptionId, $options) {
|
||||||
|
// there are no options which can be edited -> NOOP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue