Added native os notifications
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Notification;
|
||||
use App\Models\User;
|
||||
use App\Models\UserFlight;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
@@ -33,4 +34,28 @@ class UpdateDepartedFlights extends Command
|
||||
$flight->update(['departure_processed_at' => $now]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function notifyFollowersOnDeparture(UserFlight $flight): void
|
||||
{
|
||||
$user = $flight->user;
|
||||
$title = "{$user->name} is taking off!";
|
||||
$flightNumber = $flight->flight_number ? "On {$flight->flight_number} from" : 'From';
|
||||
$body = "{$flightNumber} {$flight->departureAirport->municipality} → {$flight->arrivalAirport->municipality}";
|
||||
$url = route('profile.flight', [$flight->id]);
|
||||
|
||||
$user->followers()->get()->each(function (User $follower) use ($title, $body, $url) {
|
||||
$notify = $follower->getSetting('notify_on_flight_departure');
|
||||
|
||||
if ($notify) {
|
||||
Notification::create([
|
||||
'user_id' => $follower->id,
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
'url' => $url,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user