From 7bc211dc3783646859055bd52ab09d2e3808b142 Mon Sep 17 00:00:00 2001 From: Jonathan Treffler Date: Wed, 24 Jul 2024 14:36:24 +0200 Subject: [PATCH] fix notify --- lib/Listener/CalendarListener.php | 2 +- lib/PushTransports/WebPushTransport.php | 6 ++++-- lib/Transport/Transport.php | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Listener/CalendarListener.php b/lib/Listener/CalendarListener.php index 3e2708d..f8b72c0 100644 --- a/lib/Listener/CalendarListener.php +++ b/lib/Listener/CalendarListener.php @@ -62,7 +62,7 @@ class CalendarListener implements IEventListener { foreach($subscriptions as $subscription) { $transport = $this->transportManager->getTransport($subscription->getTransport()); try { - $transport->notify($subscription->getUserId(), $collectionName, json_decode($subscription->getData(), True)); + $transport->notify($subscription->getUserId(), $collectionName, $subscription->getId()); } catch (Error $e) { $this->logger->error("transport " . $subscription->getTransport() . " failed to deliver notification to subscription " . $subscription->getId()); } diff --git a/lib/PushTransports/WebPushTransport.php b/lib/PushTransports/WebPushTransport.php index 3d6b633..134b971 100644 --- a/lib/PushTransports/WebPushTransport.php +++ b/lib/PushTransports/WebPushTransport.php @@ -79,9 +79,11 @@ class WebPushTransport extends Transport { ]; } - public function notify(string $userId, string $collectionName, $data) { + public function notify(string $userId, string $collectionName, int $subscriptionId) { $xmlService = new Service(); + $pushResource = $this->webPushSubscriptionService->findBySubscriptionId($subscriptionId)->getPushResource(); + $content = $xmlService->write('{DAV:Push}push-message', [ '{DAV:Push}topic' => $collectionName, ]); @@ -94,7 +96,7 @@ class WebPushTransport extends Transport { ]; $context = stream_context_create($options); - $result = file_get_contents($data["pushResource"], false, $context); + $result = file_get_contents($pushResource, false, $context); } public function getSubscriptionIdFromOptions($options): ?int { diff --git a/lib/Transport/Transport.php b/lib/Transport/Transport.php index eb4bce8..648f10b 100644 --- a/lib/Transport/Transport.php +++ b/lib/Transport/Transport.php @@ -67,5 +67,5 @@ abstract class Transport { // Change mutable options of the subscription (if any exist) abstract public function updateSubscription($subsciptionId, $options); - abstract public function notify(string $userId, string $collectionName, $data); + abstract public function notify(string $userId, string $collectionName, int $subscriptionId); } \ No newline at end of file