Added Phase‑1 continuation work across deep links, offline moderation queue, and admin push.
resources/js/admin/mobile/lib.
- Admin push is end‑to‑end: new backend model/migration/service/job + API endpoints, admin runtime config, push‑aware
service worker, and a settings toggle via useAdminPushSubscription. Notifications now auto‑refresh on push.
- New PHP/JS tests: admin push API feature test and queue/haptics unit tests
Added admin-specific PWA icon assets and wired them into the admin manifest, service worker, and admin shell, plus a
new “Device & permissions” card in mobile Settings with a persistent storage action and translations.
Details: public/manifest.json, public/admin-sw.js, resources/views/admin.blade.php, new icons in public/; new hook
resources/js/admin/mobile/hooks/useDevicePermissions.ts, helpers/tests in resources/js/admin/mobile/lib/
devicePermissions.ts + resources/js/admin/mobile/lib/devicePermissions.test.ts, and Settings UI updates in resources/
js/admin/mobile/SettingsPage.tsx with copy in resources/js/admin/i18n/locales/en/management.json and resources/js/
admin/i18n/locales/de/management.json.
This commit is contained in:
125
app/Jobs/SendTenantAdminPushNotification.php
Normal file
125
app/Jobs/SendTenantAdminPushNotification.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\TenantAdminPushSubscription;
|
||||
use App\Models\TenantNotificationLog;
|
||||
use App\Services\Push\AdminWebPushDispatcher;
|
||||
use App\Services\TenantAdminPushSubscriptionService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SendTenantAdminPushNotification implements ShouldQueue
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithQueue;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
public function __construct(public int $notificationLogId)
|
||||
{
|
||||
$this->onQueue('notifications');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(
|
||||
AdminWebPushDispatcher $dispatcher,
|
||||
TenantAdminPushSubscriptionService $subscriptions
|
||||
): void {
|
||||
if (! config('push.enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$notification = TenantNotificationLog::query()->find($this->notificationLogId);
|
||||
|
||||
if (! $notification) {
|
||||
return;
|
||||
}
|
||||
|
||||
$targets = TenantAdminPushSubscription::query()
|
||||
->where('tenant_id', $notification->tenant_id)
|
||||
->where('status', 'active')
|
||||
->get();
|
||||
|
||||
if ($targets->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$context = $notification->context ?? [];
|
||||
$eventId = Arr::get($context, 'event_id') ?? Arr::get($context, 'eventId');
|
||||
$event = $eventId ? Event::query()->select(['id', 'name', 'slug'])->find($eventId) : null;
|
||||
$eventName = $this->resolveEventName($event?->name);
|
||||
|
||||
$title = $eventName
|
||||
? sprintf('%s · %s', $eventName, Str::headline(str_replace('_', ' ', $notification->type)))
|
||||
: Str::headline(str_replace('_', ' ', $notification->type));
|
||||
|
||||
$payload = [
|
||||
'title' => $title,
|
||||
'body' => $notification->status === 'failed'
|
||||
? ($notification->failure_reason ?: 'Benachrichtigung fehlgeschlagen')
|
||||
: 'Neue Admin-Benachrichtigung',
|
||||
'data' => [
|
||||
'notification_id' => $notification->id,
|
||||
'event_id' => $event?->id,
|
||||
'url' => "/event-admin/mobile/notifications/{$notification->id}",
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($targets as $target) {
|
||||
try {
|
||||
$report = $dispatcher->send($target, $payload);
|
||||
|
||||
if ($report === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($report->isSuccess()) {
|
||||
$subscriptions->markDelivered($target);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($report->isSubscriptionExpired()) {
|
||||
$target->update(['status' => 'revoked']);
|
||||
}
|
||||
|
||||
$subscriptions->markFailed($target, $report->getReason());
|
||||
} catch (\Throwable $exception) {
|
||||
Log::channel('notifications')->warning('Admin web push delivery failed', [
|
||||
'subscription_id' => $target->id,
|
||||
'tenant_id' => $notification->tenant_id,
|
||||
'reason' => $exception->getMessage(),
|
||||
]);
|
||||
|
||||
$subscriptions->markFailed($target, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveEventName(mixed $name): ?string
|
||||
{
|
||||
if (is_string($name)) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
if (is_array($name)) {
|
||||
foreach ($name as $value) {
|
||||
if (is_string($value) && $value !== '') {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user