Skip to content

Commit ab1ded9

Browse files
committed
Use shouldSend for NewPostTag notifications
1 parent 1fa66b0 commit ab1ded9

File tree

2 files changed

+489
-0
lines changed

2 files changed

+489
-0
lines changed

app/Notifications/NewPostTag.php

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

1919
use App\Models\Post;
20+
use App\Models\User;
2021
use Illuminate\Bus\Queueable;
2122
use Illuminate\Contracts\Queue\ShouldQueue;
2223
use Illuminate\Notifications\Notification;
@@ -42,6 +43,34 @@ public function via(object $notifiable): array
4243
return ['database'];
4344
}
4445

46+
/**
47+
* Determine if the notification should be sent.
48+
*/
49+
public function shouldSend(User $notifiable): bool
50+
{
51+
// Do not notify self
52+
if ($this->post->user_id === $notifiable->id) {
53+
return false;
54+
}
55+
56+
// Enforce staff notifications to be sent
57+
if ($this->post->user->group->is_modo) {
58+
return true;
59+
}
60+
61+
if ($notifiable->notification?->block_notifications == 1) {
62+
return false;
63+
}
64+
65+
if (!$notifiable->notification?->show_mention_forum_post) {
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 ! \in_array($this->post->user->group_id, $notifiable->notification->json_mention_groups, true);
72+
}
73+
4574
/**
4675
* Get the array representation of the notification.
4776
*

0 commit comments

Comments
 (0)