Skip to content

Commit 5f67b3b

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

16 files changed

+94
-193
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/NewBon.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ 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
{
53-
$targetGroup = 'json_bon_groups';
54-
5551
if ($notifiable->notification?->block_notifications == 1) {
5652
return false;
5753
}
@@ -60,13 +56,10 @@ public function shouldSend(User $notifiable): bool
6056
return false;
6157
}
6258

63-
if (\is_array($notifiable->notification->$targetGroup)) {
64-
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
65-
// the expression will return false.
66-
return !\in_array($this->gift->sender->group->id, $notifiable->notification->$targetGroup, true);
67-
}
68-
69-
return true;
59+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
60+
// the expression will return false.
61+
return ! (\is_array($notifiable->notification->json_bon_groups) && \in_array($this->gift->sender->group_id, $notifiable->notification->json_bon_groups, true))
62+
;
7063
}
7164

7265
/**

app/Notifications/NewComment.php

+17-34
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
namespace App\Notifications;
1818

1919
use App\Models\Article;
20-
use App\Models\Collection;
2120
use App\Models\Comment;
2221
use App\Models\Playlist;
2322
use App\Models\Ticket;
@@ -34,7 +33,7 @@ class NewComment extends Notification
3433
/**
3534
* NewComment Constructor.
3635
*/
37-
public function __construct(public Torrent|TorrentRequest|Ticket|Playlist|Collection|Article $model, public Comment $comment)
36+
public function __construct(public Torrent|TorrentRequest|Ticket|Playlist|Article $model, public Comment $comment)
3837
{
3938
}
4039

@@ -50,8 +49,6 @@ public function via(object $notifiable): array
5049

5150
/**
5251
* Determine if the notification should be sent.
53-
*
54-
* @return bool
5552
*/
5653
public function shouldSend(User $notifiable): bool
5754
{
@@ -60,44 +57,35 @@ public function shouldSend(User $notifiable): bool
6057
return false;
6158
}
6259

63-
// Initialize target variables
64-
$targetGroup = '';
65-
$targetSetting = '';
66-
6760
// Evaluate model based settings
6861
switch (true) {
6962
case $this->model instanceof Torrent:
70-
$targetGroup = 'json_torrent_groups';
71-
$targetSetting = 'show_torrent_comment';
63+
if (!$notifiable->notification?->show_torrent_comment) {
64+
return false;
65+
}
66+
67+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
68+
// the expression will return false.
69+
return ! (\is_array($notifiable->notification->json_torrent_groups) && \in_array($this->comment->user->group_id, $notifiable->notification->json_torrent_groups, true))
70+
;
7271

73-
break;
7472
case $this->model instanceof TorrentRequest:
75-
$targetGroup = 'json_request_groups';
76-
$targetSetting = 'show_request_comment';
73+
if (!$notifiable->notification?->show_request_comment) {
74+
return false;
75+
}
76+
77+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
78+
// the expression will return false.
79+
return ! (\is_array($notifiable->notification->json_request_groups) && \in_array($this->comment->user->group_id, $notifiable->notification->json_request_groups, true))
80+
;
7781

78-
break;
7982
case $this->model instanceof Ticket:
8083
return ! ($this->model->staff_id === $this->comment->id && $this->model->staff_id !== null)
8184
;
8285

8386
case $this->model instanceof Playlist:
8487
case $this->model instanceof Article:
85-
return true;
86-
case $this->model instanceof Collection:
8788
break;
88-
default:
89-
// In the unlikely case none matches, fallback to true to not lose a notification
90-
return true;
91-
}
92-
93-
if (!$notifiable->notification?->$targetSetting) {
94-
return false;
95-
}
96-
97-
if (\is_array($notifiable->notification->$targetGroup)) {
98-
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
99-
// the expression will return false.
100-
return !\in_array($this->comment->user->group->id, $notifiable->notification->$targetGroup, true);
10189
}
10290

10391
return true;
@@ -133,11 +121,6 @@ public function toArray(object $notifiable): array
133121
'body' => $username.' has left you a comment on Playlist '.$this->model->name,
134122
'url' => '/playlists/'.$this->model->id.'#comment-'.$this->comment->id,
135123
],
136-
$this->model instanceof Collection => [
137-
'title' => 'New Collection Comment Received',
138-
'body' => $username.' has left you a comment on Collection '.$this->model->name,
139-
'url' => '/mediahub/collections/'.$this->model->id.'#comment-'.$this->comment->id,
140-
],
141124
$this->model instanceof Article => [
142125
'title' => 'New Article Comment Received',
143126
'body' => $username.' has left you a comment on Article '.$this->model->title,

app/Notifications/NewCommentTag.php

+24-25
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ public function via(object $notifiable): array
5151

5252
/**
5353
* Determine if the notification should be sent.
54-
*
55-
* @return bool
5654
*/
5755
public function shouldSend(User $notifiable): bool
5856
{
@@ -61,42 +59,43 @@ public function shouldSend(User $notifiable): bool
6159
return false;
6260
}
6361

64-
// Initialize target variables
65-
$targetGroup = 'json_mention_groups';
66-
$targetSetting = '';
67-
6862
// Evaluate model based settings
6963
switch (true) {
7064
case $this->model instanceof Torrent:
71-
$targetSetting = 'show_mention_torrent_comment';
65+
if (!$notifiable->notification?->show_mention_torrent_comment) {
66+
return false;
67+
}
68+
69+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
70+
// the expression will return false.
71+
return ! (\is_array($notifiable->notification->json_mention_groups) && \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true))
72+
;
7273

73-
break;
7474
case $this->model instanceof TorrentRequest:
75-
$targetSetting = 'show_mention_request_comment';
75+
if (!$notifiable->notification?->show_mention_request_comment) {
76+
return false;
77+
}
78+
79+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
80+
// the expression will return false.
81+
return ! (\is_array($notifiable->notification->json_mention_groups) && \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true))
82+
;
7683

77-
break;
7884
case $this->model instanceof Ticket:
7985
return ! ($this->model->staff_id === $this->comment->id);
8086
case $this->model instanceof Playlist:
8187
case $this->model instanceof Article:
82-
$targetSetting = 'show_mention_article_comment';
88+
if (!$notifiable->notification?->show_mention_article_comment) {
89+
return false;
90+
}
91+
92+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
93+
// the expression will return false.
94+
return ! (\is_array($notifiable->notification->json_mention_groups) && \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true))
95+
;
8396

84-
break;
8597
case $this->model instanceof Collection:
8698
break;
87-
default:
88-
// In the unlikely case none matches, fallback to true to not lose a notification
89-
return true;
90-
}
91-
92-
if (!$notifiable->notification?->$targetSetting) {
93-
return false;
94-
}
95-
96-
if (\is_array($notifiable->notification->$targetGroup)) {
97-
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
98-
// the expression will return false.
99-
return !\in_array($this->comment->user->group->id, $notifiable->notification->$targetGroup, true);
10099
}
101100

102101
return true;

app/Notifications/NewFollow.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,9 @@ public function via(object $notifiable): array
4444

4545
/**
4646
* Determine if the notification should be sent.
47-
*
48-
* @return bool
4947
*/
5048
public function shouldSend(User $notifiable): bool
5149
{
52-
$targetGroup = 'json_following_groups';
53-
5450
if ($notifiable->notification?->block_notifications == 1) {
5551
return false;
5652
}
@@ -59,13 +55,10 @@ public function shouldSend(User $notifiable): bool
5955
return false;
6056
}
6157

62-
if (\is_array($notifiable->notification->$targetGroup)) {
63-
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
64-
// the expression will return false.
65-
return !\in_array($this->follower->group->id, $notifiable->notification->$targetGroup, true);
66-
}
67-
68-
return true;
58+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
59+
// the expression will return false.
60+
return ! (\is_array($notifiable->notification->json_following_groups) && \in_array($this->follower->group_id, $notifiable->notification->json_following_groups, true))
61+
;
6962
}
7063

7164
/**

app/Notifications/NewPost.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
{

app/Notifications/NewPostTag.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ 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
{
53-
$targetGroup = 'json_mention_groups';
54-
5551
if ($notifiable->notification?->block_notifications == 1) {
5652
return false;
5753
}
@@ -60,13 +56,10 @@ public function shouldSend(User $notifiable): bool
6056
return false;
6157
}
6258

63-
if (\is_array($notifiable->notification->$targetGroup)) {
64-
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
65-
// the expression will return false.
66-
return !\in_array($this->post->user->group->id, $notifiable->notification->$targetGroup, true);
67-
}
68-
69-
return true;
59+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
60+
// the expression will return false.
61+
return ! (\is_array($notifiable->notification->json_mention_groups) && \in_array($this->post->user->group_id, $notifiable->notification->json_mention_groups, true))
62+
;
7063
}
7164

7265
/**

app/Notifications/NewRequestClaim.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ 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
{
53-
$targetGroup = 'json_request_groups';
54-
5551
if ($notifiable->notification?->block_notifications == 1) {
5652
return false;
5753
}
@@ -60,13 +56,10 @@ public function shouldSend(User $notifiable): bool
6056
return false;
6157
}
6258

63-
if (\is_array($notifiable->notification->$targetGroup)) {
64-
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
65-
// the expression will return false.
66-
return !\in_array($this->claim->user->group->id, $notifiable->notification->$targetGroup, true);
67-
}
68-
69-
return true;
59+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
60+
// the expression will return false.
61+
return ! (\is_array($notifiable->notification->json_request_groups) && \in_array($this->claim->user->group_id, $notifiable->notification->json_request_groups, true))
62+
;
7063
}
7164

7265
/**

app/Notifications/NewRequestFill.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ 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
{
53-
$targetGroup = 'json_request_groups';
54-
5551
if ($notifiable->notification?->block_notifications == 1) {
5652
return false;
5753
}
@@ -60,13 +56,10 @@ public function shouldSend(User $notifiable): bool
6056
return false;
6157
}
6258

63-
if (\is_array($notifiable->notification->$targetGroup)) {
64-
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
65-
// the expression will return false.
66-
return !\in_array($this->torrentRequest->filler->group->id, $notifiable->notification->$targetGroup, true);
67-
}
68-
69-
return true;
59+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
60+
// the expression will return false.
61+
return ! (\is_array($notifiable->notification->json_request_groups) && \in_array($this->torrentRequest->filler->group_id, $notifiable->notification->json_request_groups, true))
62+
;
7063
}
7164

7265
/**

app/Notifications/NewRequestFillApprove.php

+4-11
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ 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
{
53-
$targetGroup = 'json_request_groups';
54-
5551
if ($notifiable->notification?->block_notifications == 1) {
5652
return false;
5753
}
@@ -60,13 +56,10 @@ public function shouldSend(User $notifiable): bool
6056
return false;
6157
}
6258

63-
if (\is_array($notifiable->notification->$targetGroup)) {
64-
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
65-
// the expression will return false.
66-
return !\in_array($this->torrentRequest->approver->group->id, $notifiable->notification->$targetGroup, true);
67-
}
68-
69-
return true;
59+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
60+
// the expression will return false.
61+
return ! (\is_array($notifiable->notification->json_request_groups) && \in_array($this->torrentRequest->approver->group_id, $notifiable->notification->json_request_groups, true))
62+
;
7063
}
7164

7265
/**

0 commit comments

Comments
 (0)