Conditions | 6 |
Paths | 4 |
Total Lines | 38 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | public function sendNotification(User $user, string $title, string $message, string $url = '/'): void |
||
21 | { |
||
22 | $settings = $this->settingsManager->getSetting('platform.push_notification_settings'); |
||
23 | |||
24 | if (empty($settings)) { |
||
25 | return; |
||
26 | } |
||
27 | |||
28 | $decoded = json_decode($settings, true); |
||
29 | |||
30 | $gotifyUrl = $decoded['gotify_url'] ?? null; |
||
31 | $gotifyToken = $decoded['gotify_token'] ?? null; |
||
32 | $enabled = $decoded['enabled'] ?? false; |
||
33 | |||
34 | if (!$enabled || empty($gotifyUrl) || empty($gotifyToken)) { |
||
35 | return; |
||
36 | } |
||
37 | |||
38 | $subscriptions = $this->subscriptionRepository->findByUser($user); |
||
39 | |||
40 | if (empty($subscriptions)) { |
||
41 | return; |
||
42 | } |
||
43 | |||
44 | $client = HttpClient::create(); |
||
45 | |||
46 | $client->request('POST', $gotifyUrl.'/message', [ |
||
47 | 'headers' => [ |
||
48 | 'X-Gotify-Key' => $gotifyToken, |
||
49 | ], |
||
50 | 'json' => [ |
||
51 | 'title' => $title, |
||
52 | 'message' => $message, |
||
53 | 'priority' => 5, |
||
54 | 'extras' => [ |
||
55 | 'client::notification' => [ |
||
56 | 'click' => [ |
||
57 | 'url' => $url, |
||
58 | ], |
||
65 |