Skip to content

Commit 1fa66b0

Browse files
committed
Use shouldSend for NewCommentTag notifications
1 parent a3cd7f3 commit 1fa66b0

5 files changed

+1129
-0
lines changed

app/Notifications/NewCommentTag.php

+61
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use App\Models\Ticket;
2424
use App\Models\Torrent;
2525
use App\Models\TorrentRequest;
26+
use App\Models\User;
2627
use Illuminate\Bus\Queueable;
2728
use Illuminate\Contracts\Queue\ShouldQueue;
2829
use Illuminate\Notifications\Notification;
@@ -48,6 +49,66 @@ public function via(object $notifiable): array
4849
return ['database'];
4950
}
5051

52+
/**
53+
* Determine if the notification should be sent.
54+
*/
55+
public function shouldSend(User $notifiable): bool
56+
{
57+
// Do not notify self
58+
if ($this->comment->user_id === $notifiable->id) {
59+
return false;
60+
}
61+
62+
// Enforce non-anonymous staff notifications to be sent
63+
if ($this->comment->user->group->is_modo &&
64+
! $this->comment->anon) {
65+
return true;
66+
}
67+
68+
// Evaluate general settings
69+
if ($notifiable->notification?->block_notifications == 1) {
70+
return false;
71+
}
72+
73+
// Evaluate model based settings
74+
switch (true) {
75+
case $this->model instanceof Torrent:
76+
if (!$notifiable->notification?->show_mention_torrent_comment) {
77+
return false;
78+
}
79+
80+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
81+
// the expression will return false.
82+
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true);
83+
84+
case $this->model instanceof TorrentRequest:
85+
if (!$notifiable->notification?->show_mention_request_comment) {
86+
return false;
87+
}
88+
89+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
90+
// the expression will return false.
91+
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true);
92+
93+
case $this->model instanceof Ticket:
94+
return ! ($this->model->staff_id === $this->comment->id);
95+
case $this->model instanceof Playlist:
96+
case $this->model instanceof Article:
97+
if (!$notifiable->notification?->show_mention_article_comment) {
98+
return false;
99+
}
100+
101+
// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
102+
// the expression will return false.
103+
return ! \in_array($this->comment->user->group_id, $notifiable->notification->json_mention_groups, true);
104+
105+
case $this->model instanceof Collection:
106+
break;
107+
}
108+
109+
return true;
110+
}
111+
51112
/**
52113
* Get the array representation of the notification.
53114
*

0 commit comments

Comments
 (0)