PWA-Benachrichtigungen mit VAPID und Testnachricht ergänzen
This commit is contained in:
parent
7e589b58cd
commit
920b8e895a
13 changed files with 1207 additions and 2 deletions
|
|
@ -7,6 +7,7 @@ namespace App\Controllers;
|
|||
use App\Core\Auth;
|
||||
use App\Core\Image;
|
||||
use App\Models\Booking;
|
||||
use App\Models\PushSubscription;
|
||||
use App\Models\Tour;
|
||||
use App\Models\TourRoom;
|
||||
use App\Models\User;
|
||||
|
|
@ -217,9 +218,38 @@ class TourController
|
|||
}
|
||||
}
|
||||
|
||||
$this->notifyEvent($tour, false);
|
||||
|
||||
redirect('/tour');
|
||||
}
|
||||
|
||||
/** Informiert alle Push-Abos über eine neue oder abgesagte Tour. */
|
||||
private function notifyEvent(Tour $tour, bool $cancelled): void
|
||||
{
|
||||
try {
|
||||
PushSubscription::sendToAll($cancelled
|
||||
? [
|
||||
'title' => 'Tour abgesagt: ' . $tour->name,
|
||||
'body' => 'Der Termin am ' . german_date($tour->start) . ' fällt aus.',
|
||||
'url' => '/tour/' . $tour->id,
|
||||
'tag' => 'tour-' . $tour->id . '-cancelled',
|
||||
]
|
||||
: [
|
||||
'title' => 'Neue Tour: ' . $tour->name,
|
||||
'body' => german_date($tour->start) . ' – jetzt im Tourenplan ansehen.',
|
||||
'url' => '/tour/' . $tour->id,
|
||||
'tag' => 'tour-' . $tour->id,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
app_log('error', 'Push-Benachrichtigung zur Tour fehlgeschlagen', [
|
||||
'tour_id' => (int) $tour->id,
|
||||
'cancelled' => $cancelled,
|
||||
'exception' => $e::class,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function show(string $id): void
|
||||
{
|
||||
$tour = Tour::find((int) $id);
|
||||
|
|
@ -326,6 +356,7 @@ class TourController
|
|||
}
|
||||
|
||||
$current = Auth::user();
|
||||
$wasCancelled = (bool) $tour->is_cancelled;
|
||||
|
||||
validate([
|
||||
'tour_id' => 'required',
|
||||
|
|
@ -369,6 +400,10 @@ class TourController
|
|||
$tour->updated_at = now();
|
||||
$tour->save();
|
||||
|
||||
if ($tour->is_cancelled && !$wasCancelled) {
|
||||
$this->notifyEvent($tour, true);
|
||||
}
|
||||
|
||||
redirect('/tour/' . $tourId . '/edit');
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue