23
23
use App \Models \Ticket ;
24
24
use App \Models \Torrent ;
25
25
use App \Models \TorrentRequest ;
26
+ use App \Models \User ;
26
27
use Illuminate \Bus \Queueable ;
27
28
use Illuminate \Contracts \Queue \ShouldQueue ;
28
29
use Illuminate \Notifications \Notification ;
@@ -48,6 +49,66 @@ public function via(object $notifiable): array
48
49
return ['database ' ];
49
50
}
50
51
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
+
51
112
/**
52
113
* Get the array representation of the notification.
53
114
*
0 commit comments