Add guest push notifications and queue alerts

This commit is contained in:
Codex Agent
2025-11-12 20:38:49 +01:00
parent 2c412e3764
commit 574aa47ce7
34 changed files with 1806 additions and 74 deletions

View File

@@ -0,0 +1,41 @@
<?php
namespace Database\Factories;
use App\Models\Event;
use App\Models\PushSubscription;
use App\Models\Tenant;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class PushSubscriptionFactory extends Factory
{
protected $model = PushSubscription::class;
public function definition(): array
{
$endpoint = $this->faker->url();
return [
'tenant_id' => Tenant::factory(),
'event_id' => Event::factory(),
'guest_identifier' => Str::slug($this->faker->firstName()),
'device_id' => (string) Str::uuid(),
'endpoint' => $endpoint,
'endpoint_hash' => hash('sha256', $endpoint),
'public_key' => base64_encode(random_bytes(32)),
'auth_token' => base64_encode(random_bytes(16)),
'content_encoding' => 'aes128gcm',
'status' => 'active',
'language' => 'de',
'user_agent' => 'Mozilla/5.0',
];
}
public function revoked(): static
{
return $this->state([
'status' => 'revoked',
]);
}
}

View File

@@ -0,0 +1,49 @@
<?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::create('push_subscriptions', function (Blueprint $table) {
$table->id();
$table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
$table->foreignId('event_id')->constrained()->cascadeOnDelete();
$table->string('guest_identifier', 120)->nullable();
$table->string('device_id', 120);
$table->string('endpoint', 500)->unique();
$table->string('endpoint_hash', 128)->index();
$table->string('public_key', 255);
$table->string('auth_token', 255);
$table->string('content_encoding', 32)->default('aes128gcm');
$table->string('status', 32)->default('active');
$table->timestamp('expires_at')->nullable();
$table->timestamp('last_seen_at')->nullable();
$table->timestamp('last_notified_at')->nullable();
$table->timestamp('last_failed_at')->nullable();
$table->unsignedSmallInteger('failure_count')->default(0);
$table->string('language', 12)->nullable();
$table->string('user_agent', 255)->nullable();
$table->json('meta')->nullable();
$table->timestamps();
$table->index(['event_id', 'status']);
$table->index(['event_id', 'guest_identifier']);
$table->index(['event_id', 'device_id']);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('push_subscriptions');
}
};