17
17
namespace App \Notifications ;
18
18
19
19
use App \Models \Article ;
20
- use App \Models \Collection ;
21
20
use App \Models \Comment ;
22
21
use App \Models \Playlist ;
23
22
use App \Models \Ticket ;
@@ -34,7 +33,7 @@ class NewComment extends Notification
34
33
/**
35
34
* NewComment Constructor.
36
35
*/
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 )
38
37
{
39
38
}
40
39
@@ -50,8 +49,6 @@ public function via(object $notifiable): array
50
49
51
50
/**
52
51
* Determine if the notification should be sent.
53
- *
54
- * @return bool
55
52
*/
56
53
public function shouldSend (User $ notifiable ): bool
57
54
{
@@ -60,44 +57,35 @@ public function shouldSend(User $notifiable): bool
60
57
return false ;
61
58
}
62
59
63
- // Initialize target variables
64
- $ targetGroup = '' ;
65
- $ targetSetting = '' ;
66
-
67
60
// Evaluate model based settings
68
61
switch (true ) {
69
62
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
+ ;
72
71
73
- break ;
74
72
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
+ ;
77
81
78
- break ;
79
82
case $ this ->model instanceof Ticket:
80
83
return ! ($ this ->model ->staff_id === $ this ->comment ->id && $ this ->model ->staff_id !== null )
81
84
;
82
85
83
86
case $ this ->model instanceof Playlist:
84
87
case $ this ->model instanceof Article:
85
- return true ;
86
- case $ this ->model instanceof Collection:
87
88
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 );
101
89
}
102
90
103
91
return true ;
@@ -133,11 +121,6 @@ public function toArray(object $notifiable): array
133
121
'body ' => $ username .' has left you a comment on Playlist ' .$ this ->model ->name ,
134
122
'url ' => '/playlists/ ' .$ this ->model ->id .'#comment- ' .$ this ->comment ->id ,
135
123
],
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
- ],
141
124
$ this ->model instanceof Article => [
142
125
'title ' => 'New Article Comment Received ' ,
143
126
'body ' => $ username .' has left you a comment on Article ' .$ this ->model ->title ,
0 commit comments