Notifications fixes (#804)
* Emails not sending #795 #722 * Fix for news items not being sent; refactor some events; check for opt-in #722 * Formatting * Remove extra parameter
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BaseNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public $channels = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Look in the notifications.channels config and see where this particular
|
||||
// notification can go. Map it to $channels
|
||||
$klass = static::class;
|
||||
$notif_config = config('notifications.channels', []);
|
||||
if (!array_key_exists($klass, $notif_config)) {
|
||||
Log::error('Notification type '.$klass.' missing from notifications config, defaulting to mail');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->channels = $notif_config[$klass];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return $this->channels;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ use App\Notifications\Messages\UserPending;
|
||||
use App\Notifications\Messages\UserRejected;
|
||||
use App\Notifications\Notifiables\Broadcast;
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
@@ -27,6 +28,7 @@ class EventHandler extends Listener
|
||||
private static $broadcastNotifyable;
|
||||
|
||||
public static $callbacks = [
|
||||
NewsAdded::class => 'onNewsAdded',
|
||||
PirepAccepted::class => 'onPirepAccepted',
|
||||
PirepFiled::class => 'onPirepFile',
|
||||
PirepRejected::class => 'onPirepRejected',
|
||||
@@ -42,7 +44,7 @@ class EventHandler extends Listener
|
||||
/**
|
||||
* Send a notification to all of the admins
|
||||
*
|
||||
* @param \Illuminate\Notifications\Notification $notification
|
||||
* @param \App\Contracts\Notification $notification
|
||||
*/
|
||||
protected function notifyAdmins($notification)
|
||||
{
|
||||
@@ -56,8 +58,8 @@ class EventHandler extends Listener
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param \Illuminate\Notifications\Notification $notification
|
||||
* @param User $user
|
||||
* @param \App\Contracts\Notification $notification
|
||||
*/
|
||||
protected function notifyUser($user, $notification)
|
||||
{
|
||||
@@ -69,13 +71,25 @@ class EventHandler extends Listener
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a notification to all users
|
||||
* Send a notification to all users. Also can specify if a particular notification
|
||||
* requires an opt-in
|
||||
*
|
||||
* @param $notification
|
||||
* @param \App\Contracts\Notification $notification
|
||||
*/
|
||||
protected function notifyAllUsers($notification)
|
||||
protected function notifyAllUsers(\App\Contracts\Notification $notification)
|
||||
{
|
||||
$users = User::all()->get();
|
||||
$where = [];
|
||||
if ($notification->requires_opt_in === true) { // If the opt-in is required
|
||||
$where['opt_in'] = true;
|
||||
}
|
||||
|
||||
/** @var Collection $users */
|
||||
$users = User::where($where)->get();
|
||||
if (empty($users) || $users->count() === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log::info('Sending notification to '.$users->count().' users');
|
||||
|
||||
try {
|
||||
Notification::send($users, $notification);
|
||||
@@ -164,7 +178,7 @@ class EventHandler extends Listener
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify all users of a news event
|
||||
* Notify all users of a news event, but only the users which have opted in
|
||||
*
|
||||
* @param \App\Events\NewsAdded $event
|
||||
*/
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\User;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class AdminUserRegistered extends BaseNotification
|
||||
class AdminUserRegistered extends Notification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
|
||||
@@ -2,15 +2,16 @@
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\News;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class NewsAdded extends BaseNotification
|
||||
class NewsAdded extends Notification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
public $channels = ['mail'];
|
||||
public $requires_opt_in = true;
|
||||
|
||||
private $news;
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\Pirep;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
/**
|
||||
* Send the PIREP accepted message to a particular user
|
||||
*/
|
||||
class PirepAccepted extends BaseNotification
|
||||
class PirepAccepted extends Notification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\Pirep;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class PirepRejected extends BaseNotification
|
||||
class PirepRejected extends Notification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\Pirep;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class PirepSubmitted extends BaseNotification
|
||||
class PirepSubmitted extends Notification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\User;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class UserPending extends BaseNotification
|
||||
class UserPending extends Notification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\User;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class UserRegistered extends BaseNotification
|
||||
class UserRegistered extends Notification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Notifications\Messages;
|
||||
|
||||
use App\Contracts\Notification;
|
||||
use App\Models\User;
|
||||
use App\Notifications\BaseNotification;
|
||||
use App\Notifications\Channels\MailChannel;
|
||||
|
||||
class UserRejected extends BaseNotification
|
||||
class UserRejected extends Notification
|
||||
{
|
||||
use MailChannel;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user