From a849bfdc3eb2221277957fc61c531b842b29ed7d Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:00:07 +0100 Subject: [PATCH] feat: always sent notifications --- .../Internal/GeneralNotification.php | 20 +----------- app/Notifications/Server/ForceDisabled.php | 31 +++---------------- app/Notifications/Server/ForceEnabled.php | 28 ++--------------- 3 files changed, 7 insertions(+), 72 deletions(-) diff --git a/app/Notifications/Internal/GeneralNotification.php b/app/Notifications/Internal/GeneralNotification.php index 699291d16..7049e3055 100644 --- a/app/Notifications/Internal/GeneralNotification.php +++ b/app/Notifications/Internal/GeneralNotification.php @@ -2,9 +2,6 @@ namespace App\Notifications\Internal; -use App\Notifications\Channels\DiscordChannel; -use App\Notifications\Channels\TelegramChannel; -use App\Notifications\Channels\SlackChannel; use App\Notifications\Dto\DiscordMessage; use App\Notifications\Dto\SlackMessage; use Illuminate\Bus\Queueable; @@ -24,22 +21,7 @@ class GeneralNotification extends Notification implements ShouldQueue public function via(object $notifiable): array { - $channels = []; - $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); - $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); - $isSlackEnabled = data_get($notifiable, 'slack_enabled'); - - if ($isDiscordEnabled) { - $channels[] = DiscordChannel::class; - } - if ($isTelegramEnabled) { - $channels[] = TelegramChannel::class; - } - if ($isSlackEnabled) { - $channels[] = SlackChannel::class; - } - - return $channels; + return $notifiable->getEnabledChannels('general'); } public function toDiscord(): DiscordMessage diff --git a/app/Notifications/Server/ForceDisabled.php b/app/Notifications/Server/ForceDisabled.php index 1939170f6..e122849da 100644 --- a/app/Notifications/Server/ForceDisabled.php +++ b/app/Notifications/Server/ForceDisabled.php @@ -3,13 +3,9 @@ namespace App\Notifications\Server; use App\Models\Server; -use App\Notifications\Channels\DiscordChannel; -use App\Notifications\Channels\EmailChannel; -use App\Notifications\Channels\TelegramChannel; -use App\Notifications\Channels\SlackChannel; -use App\Notifications\Dto\SlackMessage; use App\Notifications\CustomEmailNotification; use App\Notifications\Dto\DiscordMessage; +use App\Notifications\Dto\SlackMessage; use Illuminate\Notifications\Messages\MailMessage; class ForceDisabled extends CustomEmailNotification @@ -21,25 +17,7 @@ class ForceDisabled extends CustomEmailNotification public function via(object $notifiable): array { - $channels = []; - $isEmailEnabled = isEmailEnabled($notifiable); - $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); - $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); - $isSlackEnabled = data_get($notifiable, 'slack_enabled'); - if ($isDiscordEnabled) { - $channels[] = DiscordChannel::class; - } - if ($isEmailEnabled) { - $channels[] = EmailChannel::class; - } - if ($isTelegramEnabled) { - $channels[] = TelegramChannel::class; - } - if ($isSlackEnabled) { - $channels[] = SlackChannel::class; - } - - return $channels; + return $notifiable->getEnabledChannels('server_force_disabled'); } public function toMail(): MailMessage @@ -73,13 +51,12 @@ class ForceDisabled extends CustomEmailNotification ]; } - public function toSlack(): SlackMessage { - $title = "Server disabled"; + $title = 'Server disabled'; $description = "Server ({$this->server->name}) disabled because it is not paid!\n"; $description .= "All automations and integrations are stopped.\n\n"; - $description .= "Please update your subscription to enable the server again: https://app.coolify.io/subscriptions"; + $description .= 'Please update your subscription to enable the server again: https://app.coolify.io/subscriptions'; return new SlackMessage( title: $title, diff --git a/app/Notifications/Server/ForceEnabled.php b/app/Notifications/Server/ForceEnabled.php index 4b6181e19..a0e0a8b59 100644 --- a/app/Notifications/Server/ForceEnabled.php +++ b/app/Notifications/Server/ForceEnabled.php @@ -3,13 +3,9 @@ namespace App\Notifications\Server; use App\Models\Server; -use App\Notifications\Channels\DiscordChannel; -use App\Notifications\Channels\EmailChannel; -use App\Notifications\Channels\TelegramChannel; -use App\Notifications\Channels\SlackChannel; -use App\Notifications\Dto\SlackMessage; use App\Notifications\CustomEmailNotification; use App\Notifications\Dto\DiscordMessage; +use App\Notifications\Dto\SlackMessage; use Illuminate\Notifications\Messages\MailMessage; class ForceEnabled extends CustomEmailNotification @@ -21,25 +17,7 @@ class ForceEnabled extends CustomEmailNotification public function via(object $notifiable): array { - $channels = []; - $isEmailEnabled = isEmailEnabled($notifiable); - $isDiscordEnabled = data_get($notifiable, 'discord_enabled'); - $isTelegramEnabled = data_get($notifiable, 'telegram_enabled'); - $isSlackEnabled = data_get($notifiable, 'slack_enabled'); - if ($isDiscordEnabled) { - $channels[] = DiscordChannel::class; - } - if ($isEmailEnabled) { - $channels[] = EmailChannel::class; - } - if ($isTelegramEnabled) { - $channels[] = TelegramChannel::class; - } - if ($isSlackEnabled) { - $channels[] = SlackChannel::class; - } - - return $channels; + return $notifiable->getEnabledChannels('server_force_enabled'); } public function toMail(): MailMessage @@ -69,7 +47,6 @@ class ForceEnabled extends CustomEmailNotification ]; } - public function toSlack(): SlackMessage { return new SlackMessage( @@ -78,5 +55,4 @@ class ForceEnabled extends CustomEmailNotification color: SlackMessage::successColor() ); } - }