Skip to content

Commit

Permalink
Code cleanup & improvements
Browse files Browse the repository at this point in the history
Co-authored-by: Roardom <[email protected]>
  • Loading branch information
Obi-Wana and Roardom committed Feb 1, 2025
1 parent ab1ded9 commit 5854afc
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 27 deletions.
9 changes: 0 additions & 9 deletions app/Http/Livewire/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 0 additions & 2 deletions app/Notifications/NewComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
;
Expand Down
3 changes: 0 additions & 3 deletions app/Notifications/NewCommentTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/NewPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions app/Notifications/NewUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
17 changes: 9 additions & 8 deletions database/factories/UserNotificationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5854afc

Please sign in to comment.