From 24e8cd977e4e4cb71c0054793a197cf2927518e9 Mon Sep 17 00:00:00 2001 From: Kris Date: Sun, 11 Aug 2024 10:18:40 +0200 Subject: [PATCH] :bug: fix admin notification for denied events (#2840) --- .../Frontend/Admin/EventController.php | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Frontend/Admin/EventController.php b/app/Http/Controllers/Frontend/Admin/EventController.php index d1ca27bac..97099bc8f 100644 --- a/app/Http/Controllers/Frontend/Admin/EventController.php +++ b/app/Http/Controllers/Frontend/Admin/EventController.php @@ -17,7 +17,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Http; use Illuminate\Validation\Rules\Enum; use Illuminate\View\View; @@ -109,20 +108,23 @@ public function denySuggestion(Request $request): RedirectResponse { ]); $eventSuggestion = EventSuggestion::find($validated['id']); $eventSuggestion->update(['processed' => true]); - if (!App::runningUnitTests() && config('services.telegram.admin.active')) { - Http::post(config('app.admin.notification.url'), [ - 'chat_id' => config('services.telegram.admin.chat_id'), - 'text' => strtr("Event suggestion denied" . PHP_EOL . - "Title: :name" . PHP_EOL - . "Denial reason: :reason" . PHP_EOL - . "Denial user: :username" . PHP_EOL, [ - ':name' => $eventSuggestion->name, - ':reason' => EventRejectionReason::from($validated['rejectionReason'])->getReason(), - ':username' => auth()->user()->username, - ]), - 'parse_mode' => 'HTML', - ]); + if (!App::runningUnitTests() && TelegramService::isAdminActive()) { + try { + TelegramService::admin()->sendMessage( + strtr("Event suggestion denied" . PHP_EOL . + "Title: :name" . PHP_EOL + . "Denial reason: :reason" . PHP_EOL + . "Denial user: :username" . PHP_EOL, [ + ':name' => $eventSuggestion->name, + ':reason' => EventRejectionReason::from($validated['rejectionReason'])->getReason(), + ':username' => auth()->user()->username, + ]) + ); + } catch (TelegramException $exception) { + report($exception); + } } + $eventSuggestion->user->notify( new EventSuggestionProcessed( $eventSuggestion,