From 4ba4173f8bc866283a9bc06db589968f1d318a19 Mon Sep 17 00:00:00 2001 From: Jay <73784120+Obi-Wana@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:14:08 +0000 Subject: [PATCH] Code cleanup & improvements Co-authored-by: Roardom <78790963+Roardom@users.noreply.github.com> --- app/Http/Livewire/Comments.php | 9 --------- app/Notifications/NewComment.php | 2 -- app/Notifications/NewCommentTag.php | 3 --- app/Notifications/NewUpload.php | 2 -- database/factories/UserNotificationFactory.php | 17 +++++++++-------- 5 files changed, 9 insertions(+), 24 deletions(-) diff --git a/app/Http/Livewire/Comments.php b/app/Http/Livewire/Comments.php index 81413de446..f7f8bf2a3e 100644 --- a/app/Http/Livewire/Comments.php +++ b/app/Http/Livewire/Comments.php @@ -136,17 +136,8 @@ final public function postComment(): void break; case $this->model instanceof Article: - User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment)); - - break; case $this->model instanceof Playlist: - User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment)); - - break; case $this->model instanceof TorrentRequest: - User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment)); - - break; case $this->model instanceof Torrent: User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment)); diff --git a/app/Notifications/NewComment.php b/app/Notifications/NewComment.php index 2d89096993..a6196efce6 100644 --- a/app/Notifications/NewComment.php +++ b/app/Notifications/NewComment.php @@ -67,7 +67,6 @@ public function shouldSend(User $notifiable): bool // If the sender's group ID is found in the "Block all notifications from the selected groups" array, // the expression will return false. return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_torrent_groups, true); - case $this->model instanceof TorrentRequest: if (!$notifiable->notification?->show_request_comment) { return false; @@ -76,7 +75,6 @@ public function shouldSend(User $notifiable): bool // If the sender's group ID is found in the "Block all notifications from the selected groups" array, // the expression will return false. return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_request_groups, true); - case $this->model instanceof Ticket: return ! ($this->model->staff_id === $this->comment->id && $this->model->staff_id !== null) ; diff --git a/app/Notifications/NewCommentTag.php b/app/Notifications/NewCommentTag.php index 59d53269d0..82f4bf8f1b 100644 --- a/app/Notifications/NewCommentTag.php +++ b/app/Notifications/NewCommentTag.php @@ -69,7 +69,6 @@ public function shouldSend(User $notifiable): bool // If the sender's group ID is found in the "Block all notifications from the selected groups" array, // the expression will return false. return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true); - case $this->model instanceof TorrentRequest: if (!$notifiable->notification?->show_mention_request_comment) { return false; @@ -78,7 +77,6 @@ public function shouldSend(User $notifiable): bool // If the sender's group ID is found in the "Block all notifications from the selected groups" array, // the expression will return false. return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true); - case $this->model instanceof Ticket: return ! ($this->model->staff_id === $this->comment->id); case $this->model instanceof Playlist: @@ -90,7 +88,6 @@ public function shouldSend(User $notifiable): bool // If the sender's group ID is found in the "Block all notifications from the selected groups" array, // the expression will return false. return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true); - case $this->model instanceof Collection: break; } diff --git a/app/Notifications/NewUpload.php b/app/Notifications/NewUpload.php index 60f3bb6895..44cb3e4b56 100644 --- a/app/Notifications/NewUpload.php +++ b/app/Notifications/NewUpload.php @@ -45,8 +45,6 @@ public function via(object $notifiable): array /** * Determine if the notification should be sent. - * - * @return bool */ public function shouldSend(User $notifiable): bool { diff --git a/database/factories/UserNotificationFactory.php b/database/factories/UserNotificationFactory.php index a6c72a5583..95d9be1bd3 100644 --- a/database/factories/UserNotificationFactory.php +++ b/database/factories/UserNotificationFactory.php @@ -16,6 +16,7 @@ namespace Database\Factories; +use App\Models\Group; use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; use App\Models\UserNotification; @@ -57,14 +58,14 @@ public function definition(): array 'show_torrent_thank' => $this->faker->boolean(), 'show_account_follow' => $this->faker->boolean(), 'show_account_unfollow' => $this->faker->boolean(), - 'json_account_groups' => $this->faker->word(), - 'json_bon_groups' => $this->faker->word(), - 'json_mention_groups' => $this->faker->word(), - 'json_request_groups' => $this->faker->word(), - 'json_torrent_groups' => $this->faker->word(), - 'json_forum_groups' => $this->faker->word(), - 'json_following_groups' => $this->faker->word(), - 'json_subscription_groups' => $this->faker->word(), + 'json_account_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(), + 'json_bon_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(), + 'json_mention_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(), + 'json_request_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(), + 'json_torrent_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(), + 'json_forum_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(), + 'json_following_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(), + 'json_subscription_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(), ]; } }