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 de35dd4e05..7c27a5beaf 100644 --- a/app/Notifications/NewComment.php +++ b/app/Notifications/NewComment.php @@ -78,7 +78,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; @@ -87,7 +86,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 800bf66483..e5762df329 100644 --- a/app/Notifications/NewCommentTag.php +++ b/app/Notifications/NewCommentTag.php @@ -80,7 +80,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; @@ -89,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 Ticket: return ! ($this->model->staff_id === $this->comment->id); case $this->model instanceof Playlist: @@ -101,7 +99,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/NewPost.php b/app/Notifications/NewPost.php index 477218ec3d..da3d798f27 100644 --- a/app/Notifications/NewPost.php +++ b/app/Notifications/NewPost.php @@ -48,7 +48,7 @@ public function via(object $notifiable): array */ public function shouldSend(User $notifiable): bool { - // Do not notify the poster themself + // Do not notify self if ($this->post->user_id === $notifiable->id || $notifiable->notification?->block_notifications == 1) { return false; diff --git a/app/Notifications/NewUpload.php b/app/Notifications/NewUpload.php index 00c8f9caab..699488078c 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(), ]; } } diff --git a/tests/Feature/Notifications/NewCommentTorrentNotificationTest.php b/tests/Feature/Notifications/NewCommentTorrentNotificationTest.php index 5dc105c6ca..4556375bc5 100644 --- a/tests/Feature/Notifications/NewCommentTorrentNotificationTest.php +++ b/tests/Feature/Notifications/NewCommentTorrentNotificationTest.php @@ -73,7 +73,7 @@ Notification::assertCount(0); }); -test('comment a torent creates a notification for the uploader', function (): void { +test('comment a torrent creates a notification for the uploader', function (): void { Notification::fake(); // Required for ChatRepository() diff --git a/tests/Feature/Notifications/NewRequestFillApproveNotificationTest.php b/tests/Feature/Notifications/NewRequestFillApproveNotificationTest.php index 7e991fd78d..981cbc5c93 100644 --- a/tests/Feature/Notifications/NewRequestFillApproveNotificationTest.php +++ b/tests/Feature/Notifications/NewRequestFillApproveNotificationTest.php @@ -255,7 +255,7 @@ Notification::assertCount(0); }); -test('accept a request fill creates a notification for the filler when reqeust notifications are disabled for specific group', function (): void { +test('accept a request fill creates a notification for the filler when request notifications are disabled for specific group', function (): void { Notification::fake(); // Required for ChatRepository()