Added sockets for notifications
This commit is contained in:
@@ -21,20 +21,17 @@ class UpdateDepartedFlights extends Command
|
||||
{
|
||||
$now = now()->utc();
|
||||
|
||||
$now = now()->utc();
|
||||
|
||||
$userFlights = UserFlight::where('departure_date', '<=', $now->toDateTimeString())
|
||||
->where('departure_date', '>', $now->copy()->subMinute()->toDateTimeString())
|
||||
->where(function ($query) {
|
||||
$query->whereNull('departure_processed_at')
|
||||
->orWhereColumn('departure_processed_at', '<', 'departure_date');
|
||||
})
|
||||
->get();
|
||||
|
||||
$this->info("Found {$userFlights->count()} flights.");
|
||||
|
||||
foreach ($userFlights as $flight) {
|
||||
$flight->touch();
|
||||
$flight->update(['departure_processed_at' => $now]);
|
||||
}
|
||||
|
||||
$this->info("Touching flight {$flight->id}");
|
||||
$result = $flight->touch();
|
||||
$this->info("Touch result: " . var_export($result, true));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Events;
|
||||
use App\Models\Notification;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class NotificationCreated implements ShouldBroadcast
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UserFlight extends Model
|
||||
@@ -30,12 +31,14 @@ class UserFlight extends Model
|
||||
'crew_type_id',
|
||||
'note',
|
||||
'auto_update',
|
||||
'departure_processed_at'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'departure_date' => 'immutable_datetime',
|
||||
'arrival_date' => 'immutable_datetime',
|
||||
'auto_update' => 'boolean',
|
||||
'departure_processed_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
@@ -50,9 +53,17 @@ class UserFlight extends Model
|
||||
'livery_url',
|
||||
'scope',
|
||||
'range',
|
||||
'region_range'
|
||||
'region_range',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (UserFlight $flight) {
|
||||
$flight->departure_processed_at = now();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function calculateGreatCircleDistance(): float{
|
||||
$earthRadiusKm = 6371;
|
||||
[$depLat, $depLong] = [$this->departureAirport->latitude_deg, $this->departureAirport->longitude_deg];
|
||||
@@ -182,7 +193,8 @@ class UserFlight extends Model
|
||||
return !$this->isDomestic();
|
||||
}
|
||||
|
||||
public function otherUsersOnFlight(){
|
||||
public function otherUsersOnFlight(): Collection
|
||||
{
|
||||
return UserFlight::where('user_id', '!=', $this->user_id)
|
||||
->where('departure_airport_id', $this->departure_airport_id)
|
||||
->where('arrival_airport_id', $this->arrival_airport_id)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('user_flights', function (Blueprint $table) {
|
||||
$table->timestamp('departure_processed_at')->nullable()->after('departure_date');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
||||
@@ -6,5 +6,6 @@ php artisan config:cache
|
||||
php artisan migrate --force
|
||||
|
||||
crond -f -l 8 &
|
||||
php artisan reverb:start --host=0.0.0.0 --port=8080 &
|
||||
php-fpm -D
|
||||
nginx -g 'daemon off;'
|
||||
|
||||
Vendored
+7
-5
@@ -7,12 +7,14 @@ import Pusher from 'pusher-js';
|
||||
|
||||
window.Pusher = Pusher;
|
||||
|
||||
const { data } = await axios.get('/broadcasting/config');
|
||||
|
||||
window.Echo = new Echo({
|
||||
broadcaster: 'reverb',
|
||||
key: import.meta.env.VITE_REVERB_APP_KEY,
|
||||
wsHost: import.meta.env.VITE_REVERB_HOST,
|
||||
wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
|
||||
wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
|
||||
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
|
||||
key: data.key,
|
||||
wsHost: data.host,
|
||||
wsPort: data.port,
|
||||
wssPort: data.port,
|
||||
forceTLS: data.scheme === 'https',
|
||||
enabledTransports: ['ws', 'wss'],
|
||||
});
|
||||
|
||||
+8
-1
@@ -20,7 +20,14 @@ use Inertia\Inertia;
|
||||
Route::get('/', [UserProfileController::class, 'index'])->name('home');
|
||||
|
||||
Route::get('/splash', [HomePageController::class, 'splash'])->name('splash');
|
||||
|
||||
Route::get('/broadcasting/config', function () {
|
||||
return response()->json([
|
||||
'key' => config('broadcasting.connections.reverb.key'),
|
||||
'host' => config('broadcasting.connections.reverb.options.host'),
|
||||
'port' => config('broadcasting.connections.reverb.options.port'),
|
||||
'scheme' => config('broadcasting.connections.reverb.options.scheme'),
|
||||
]);
|
||||
});
|
||||
|
||||
Route::get('/dashboard', function () {
|
||||
return Inertia::render('Dashboard');
|
||||
|
||||
Reference in New Issue
Block a user