Skip to content

Commit

Permalink
Use shouldSend for NewPostTag notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Obi-Wana committed Feb 1, 2025
1 parent df522d5 commit a8c5fe9
Show file tree
Hide file tree
Showing 2 changed files with 408 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/Notifications/NewPostTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace App\Notifications;

use App\Models\Post;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
Expand All @@ -42,6 +43,25 @@ public function via(object $notifiable): array
return ['database'];
}

/**
* Determine if the notification should be sent.
*/
public function shouldSend(User $notifiable): bool
{
if ($this->post->user_id === $notifiable->id ||
$notifiable->notification?->block_notifications == 1) {
return false;
}

if (!$notifiable->notification?->show_mention_forum_post) {
return false;
}

// If the sender's group ID is found in the "Block all notifications from the selected groups" array,
// the expression will return false.
return ! \in_array($this->post->user->group_id, $notifiable->notification->json_mention_groups, true);
}

/**
* Get the array representation of the notification.
*
Expand Down
Loading

0 comments on commit a8c5fe9

Please sign in to comment.