Skip to content

Commit 93366d5

Browse files
Obi-WanaRoardom
andcommitted
Code cleanup & improvements
Co-authored-by: Roardom <78790963+Roardom@users.noreply.github.com>
1 parent be9f450 commit 93366d5

File tree

8 files changed

+12
-27
lines changed

8 files changed

+12
-27
lines changed

app/Http/Livewire/Comments.php

-9
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,8 @@ final public function postComment(): void
136136

137137
break;
138138
case $this->model instanceof Article:
139-
User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment));
140-
141-
break;
142139
case $this->model instanceof Playlist:
143-
User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment));
144-
145-
break;
146140
case $this->model instanceof TorrentRequest:
147-
User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment));
148-
149-
break;
150141
case $this->model instanceof Torrent:
151142
User::find($this->model->user_id)?->notify(new NewComment($this->model, $comment));
152143

app/Notifications/NewComment.php

-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public function shouldSend(User $notifiable): bool
7878
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
7979
// the expression will return false.
8080
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_torrent_groups, true);
81-
8281
case $this->model instanceof TorrentRequest:
8382
if (!$notifiable->notification?->show_request_comment) {
8483
return false;
@@ -87,7 +86,6 @@ public function shouldSend(User $notifiable): bool
8786
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
8887
// the expression will return false.
8988
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_request_groups, true);
90-
9189
case $this->model instanceof Ticket:
9290
return ! ($this->model->staff_id === $this->comment->id && $this->model->staff_id !== null)
9391
;

app/Notifications/NewCommentTag.php

-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public function shouldSend(User $notifiable): bool
8080
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
8181
// the expression will return false.
8282
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true);
83-
8483
case $this->model instanceof TorrentRequest:
8584
if (!$notifiable->notification?->show_mention_request_comment) {
8685
return false;
@@ -89,7 +88,6 @@ public function shouldSend(User $notifiable): bool
8988
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
9089
// the expression will return false.
9190
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true);
92-
9391
case $this->model instanceof Ticket:
9492
return ! ($this->model->staff_id === $this->comment->id);
9593
case $this->model instanceof Playlist:
@@ -101,7 +99,6 @@ public function shouldSend(User $notifiable): bool
10199
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
102100
// the expression will return false.
103101
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true);
104-
105102
case $this->model instanceof Collection:
106103
break;
107104
}

app/Notifications/NewPost.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function via(object $notifiable): array
4848
*/
4949
public function shouldSend(User $notifiable): bool
5050
{
51-
// Do not notify the poster themself
51+
// Do not notify self
5252
if ($this->post->user_id === $notifiable->id ||
5353
$notifiable->notification?->block_notifications == 1) {
5454
return false;

app/Notifications/NewUpload.php

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ public function via(object $notifiable): array
4545

4646
/**
4747
* Determine if the notification should be sent.
48-
*
49-
* @return bool
5048
*/
5149
public function shouldSend(User $notifiable): bool
5250
{

database/factories/UserNotificationFactory.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
namespace Database\Factories;
1818

19+
use App\Models\Group;
1920
use App\Models\User;
2021
use Illuminate\Database\Eloquent\Factories\Factory;
2122
use App\Models\UserNotification;
@@ -57,14 +58,14 @@ public function definition(): array
5758
'show_torrent_thank' => $this->faker->boolean(),
5859
'show_account_follow' => $this->faker->boolean(),
5960
'show_account_unfollow' => $this->faker->boolean(),
60-
'json_account_groups' => $this->faker->word(),
61-
'json_bon_groups' => $this->faker->word(),
62-
'json_mention_groups' => $this->faker->word(),
63-
'json_request_groups' => $this->faker->word(),
64-
'json_torrent_groups' => $this->faker->word(),
65-
'json_forum_groups' => $this->faker->word(),
66-
'json_following_groups' => $this->faker->word(),
67-
'json_subscription_groups' => $this->faker->word(),
61+
'json_account_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
62+
'json_bon_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
63+
'json_mention_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
64+
'json_request_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
65+
'json_torrent_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
66+
'json_forum_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
67+
'json_following_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
68+
'json_subscription_groups' => Group::factory()->count(3)->create()->pluck('id')->toArray(),
6869
];
6970
}
7071
}

tests/Feature/Notifications/NewCommentTorrentNotificationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
Notification::assertCount(0);
7474
});
7575

76-
test('comment a torent creates a notification for the uploader', function (): void {
76+
test('comment a torrent creates a notification for the uploader', function (): void {
7777
Notification::fake();
7878

7979
// Required for ChatRepository()

tests/Feature/Notifications/NewRequestFillApproveNotificationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
Notification::assertCount(0);
256256
});
257257

258-
test('accept a request fill creates a notification for the filler when reqeust notifications are disabled for specific group', function (): void {
258+
test('accept a request fill creates a notification for the filler when request notifications are disabled for specific group', function (): void {
259259
Notification::fake();
260260

261261
// Required for ChatRepository()

0 commit comments

Comments
 (0)