From 141894c2afe864e62c5c3be4436cea334e80b8c5 Mon Sep 17 00:00:00 2001 From: Alex Justesen <1144087+alexjustesen@users.noreply.github.com> Date: Mon, 24 Nov 2025 11:32:09 -0500 Subject: [PATCH] Add user database notifications for completed and failed speedtests --- app/Listeners/ProcessCompletedSpeedtest.php | 44 +++++++++++++++++++++ app/Listeners/ProcessFailedSpeedtest.php | 44 +++++++++++++++++++++ lang/en/general.php | 1 + lang/en/results.php | 1 + 4 files changed, 90 insertions(+) create mode 100644 app/Listeners/ProcessCompletedSpeedtest.php create mode 100644 app/Listeners/ProcessFailedSpeedtest.php diff --git a/app/Listeners/ProcessCompletedSpeedtest.php b/app/Listeners/ProcessCompletedSpeedtest.php new file mode 100644 index 000000000..01bf317e6 --- /dev/null +++ b/app/Listeners/ProcessCompletedSpeedtest.php @@ -0,0 +1,44 @@ +result; + + if ($result->dispatched_by && ! $result->scheduled) { + $this->notifyDispatchingUser($result); + } + } + + /** + * Notify the user who dispatched the speedtest. + */ + private function notifyDispatchingUser(Result $result): void + { + $user = User::find($result->dispatched_by); + + $user->notify( + Notification::make() + ->title(__('results.speedtest_completed')) + ->actions([ + Action::make('view') + ->label(__('general.view')) + ->url(route('filament.admin.resources.results.index')), + ]) + ->success() + ->toDatabase(), + ); + } +} diff --git a/app/Listeners/ProcessFailedSpeedtest.php b/app/Listeners/ProcessFailedSpeedtest.php new file mode 100644 index 000000000..d11e5e7a0 --- /dev/null +++ b/app/Listeners/ProcessFailedSpeedtest.php @@ -0,0 +1,44 @@ +result; + + if ($result->dispatched_by && ! $result->scheduled) { + $this->notifyDispatchingUser($result); + } + } + + /** + * Notify the user who dispatched the speedtest. + */ + private function notifyDispatchingUser(Result $result): void + { + $user = User::find($result->dispatched_by); + + $user->notify( + Notification::make() + ->title(__('results.speedtest_failed')) + ->actions([ + Action::make('view') + ->label(__('general.view')) + ->url(route('filament.admin.resources.results.index')), + ]) + ->warning() + ->toDatabase(), + ); + } +} diff --git a/lang/en/general.php b/lang/en/general.php index 41f3add2c..c29e775d1 100644 --- a/lang/en/general.php +++ b/lang/en/general.php @@ -16,6 +16,7 @@ 'no' => 'No', 'options' => 'Options', 'details' => 'Details', + 'view' => 'View', // Common labels 'name' => 'Name', diff --git a/lang/en/results.php b/lang/en/results.php index 1cd083492..f59df96d8 100644 --- a/lang/en/results.php +++ b/lang/en/results.php @@ -63,6 +63,7 @@ // Notifications 'speedtest_started' => 'Speedtest started', 'speedtest_completed' => 'Speedtest completed', + 'speedtest_failed' => 'Speedtest failed', 'download_threshold_breached' => 'Download threshold breached!', 'upload_threshold_breached' => 'Upload threshold breached!', 'ping_threshold_breached' => 'Ping threshold breached!',