#124: Converted the comment-related e-mails to be queueable

This commit is contained in:
Andy Heathershaw 2019-07-14 15:58:12 +01:00
parent e794f99ead
commit 4905dd1caa
9 changed files with 211 additions and 26 deletions

View File

@ -6,14 +6,13 @@ use App\Album;
use App\Facade\Theme; use App\Facade\Theme;
use App\Facade\UserConfig; use App\Facade\UserConfig;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Mail\PhotoCommentApproved; use App\Notifications\PhotoCommentApproved;
use App\Mail\PhotoCommentApprovedUser; use App\Notifications\PhotoCommentApprovedUser;
use App\Mail\PhotoCommentRepliedTo; use App\Notifications\PhotoCommentRepliedTo;
use App\Photo; use App\Photo;
use App\PhotoComment; use App\PhotoComment;
use App\User; use App\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
class PhotoCommentController extends Controller class PhotoCommentController extends Controller
@ -344,16 +343,17 @@ class PhotoCommentController extends Controller
*/ */
private function notifyAlbumOwnerAndPoster(Album $album, Photo $photo, PhotoComment $comment) private function notifyAlbumOwnerAndPoster(Album $album, Photo $photo, PhotoComment $comment)
{ {
/** @var User $owner */
$owner = $album->user; $owner = $album->user;
Mail::to($owner)->send(new PhotoCommentApproved($owner, $album, $photo, $comment)); $owner->notify(new PhotoCommentApproved($album, $photo, $comment));
// Also send a notification to the comment poster // Also send a notification to the comment poster
$poster = new User(); $poster = new User();
$poster->name = $comment->authorDisplayName(); $poster->name = $comment->authorDisplayName();
$poster->email = $comment->authorEmail(); $poster->email = $comment->authorEmail();
Mail::to($poster)->send(new PhotoCommentApprovedUser($poster, $album, $photo, $comment)); $poster->notify(new PhotoCommentApprovedUser($album, $photo, $comment));
// Send notification to the parent comment owner (if this is a reply) // Send notification to the parent comment owner (if this is a reply)
if (!is_null($comment->parent_comment_id)) if (!is_null($comment->parent_comment_id))
@ -369,7 +369,7 @@ class PhotoCommentController extends Controller
$parentPoster->name = $parentComment->authorDisplayName(); $parentPoster->name = $parentComment->authorDisplayName();
$parentPoster->email = $parentComment->authorEmail(); $parentPoster->email = $parentComment->authorEmail();
Mail::to($parentPoster)->send(new PhotoCommentRepliedTo($parentPoster, $album, $photo, $comment)); $parentPoster->notify(new PhotoCommentRepliedTo($album, $photo, $comment));
} }
} }
} }

View File

@ -8,21 +8,16 @@ use App\Facade\UserConfig;
use App\Helpers\DbHelper; use App\Helpers\DbHelper;
use App\Helpers\PermissionsHelper; use App\Helpers\PermissionsHelper;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\StorePhotoCommentRequest; use App\Notifications\ModeratePhotoComment;
use App\Mail\ModeratePhotoComment; use App\Notifications\PhotoCommentApproved;
use App\Mail\PhotoCommentApproved; use App\Notifications\PhotoCommentApprovedUser;
use App\Mail\PhotoCommentApprovedUser; use App\Notifications\PhotoCommentRepliedTo;
use App\Mail\PhotoCommentRepliedTo;
use App\Permission;
use App\Photo; use App\Photo;
use App\PhotoComment; use App\PhotoComment;
use App\User; use App\User;
use App\UserActivity; use App\UserActivity;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Mail;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
class PhotoCommentController extends Controller class PhotoCommentController extends Controller
@ -315,7 +310,7 @@ class PhotoCommentController extends Controller
/** @var User $moderator */ /** @var User $moderator */
foreach ($moderators as $moderator) foreach ($moderators as $moderator)
{ {
Mail::to($moderator)->send(new ModeratePhotoComment($moderator, $album, $photo, $comment)); $moderator->notify(new ModeratePhotoComment($album, $photo, $comment));
} }
} }
@ -327,16 +322,17 @@ class PhotoCommentController extends Controller
*/ */
private function notifyAlbumOwnerAndPoster(Album $album, Photo $photo, PhotoComment $comment) private function notifyAlbumOwnerAndPoster(Album $album, Photo $photo, PhotoComment $comment)
{ {
/** @var User $owner */
$owner = $album->user; $owner = $album->user;
Mail::to($owner)->send(new PhotoCommentApproved($owner, $album, $photo, $comment)); $owner->notify(new PhotoCommentApproved($album, $photo, $comment));
// Also send a notification to the comment poster // Also send a notification to the comment poster
$poster = new User(); $poster = new User();
$poster->name = $comment->authorDisplayName(); $poster->name = $comment->authorDisplayName();
$poster->email = $comment->authorEmail(); $poster->email = $comment->authorEmail();
Mail::to($poster)->send(new PhotoCommentApprovedUser($poster, $album, $photo, $comment)); $poster->notify(new PhotoCommentApprovedUser($album, $photo, $comment));
// Send notification to the parent comment owner (if this is a reply) // Send notification to the parent comment owner (if this is a reply)
if (!is_null($comment->parent_comment_id)) if (!is_null($comment->parent_comment_id))
@ -352,7 +348,7 @@ class PhotoCommentController extends Controller
$parentPoster->name = $parentComment->authorDisplayName(); $parentPoster->name = $parentComment->authorDisplayName();
$parentPoster->email = $parentComment->authorEmail(); $parentPoster->email = $parentComment->authorEmail();
Mail::to($parentPoster)->send(new PhotoCommentRepliedTo($parentPoster, $album, $photo, $comment)); $parentPoster->notify(new PhotoCommentRepliedTo($album, $photo, $comment));
} }
} }

View File

@ -8,10 +8,9 @@ use App\Photo;
use App\PhotoComment; use App\PhotoComment;
use App\User; use App\User;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
class ModeratePhotoComment extends Mailable class ModeratePhotoComment extends MailableBase
{ {
use Queueable, SerializesModels; use Queueable, SerializesModels;

View File

@ -8,14 +8,13 @@ use App\Photo;
use App\PhotoComment; use App\PhotoComment;
use App\User; use App\User;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**
* E-mail notification to the owner of an album that is sent when a new comment has been approved in their album. * E-mail notification to the owner of an album that is sent when a new comment has been approved in their album.
* @package App\Mail * @package App\Mail
*/ */
class PhotoCommentApproved extends Mailable class PhotoCommentApproved extends MailableBase
{ {
use Queueable, SerializesModels; use Queueable, SerializesModels;

View File

@ -8,14 +8,13 @@ use App\Photo;
use App\PhotoComment; use App\PhotoComment;
use App\User; use App\User;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**
* E-mail notification to the poster of a comment that is sent when it has been approved. * E-mail notification to the poster of a comment that is sent when it has been approved.
* @package App\Mail * @package App\Mail
*/ */
class PhotoCommentApprovedUser extends Mailable class PhotoCommentApprovedUser extends MailableBase
{ {
use Queueable, SerializesModels; use Queueable, SerializesModels;

View File

@ -0,0 +1,48 @@
<?php
namespace App\Notifications;
use App\Album;
use App\Mail\MailableBase;
use App\Mail\ModeratePhotoComment as ModeratePhotoCommentMailable;
use App\Photo;
use App\PhotoComment;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class ModeratePhotoComment extends Notification
{
use Queueable;
use DatabaseEmailNotification;
private $album;
private $comment;
private $photo;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Album $album, Photo $photo, PhotoComment $comment)
{
$this->album = $album;
$this->photo = $photo;
$this->comment = $comment;
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage|MailableBase
*/
public function toMail($notifiable)
{
$mailable = new ModeratePhotoCommentMailable($notifiable, $this->album, $this->photo, $this->comment);
$this->setPropertiesOnMailable($mailable, $notifiable);
return $mailable;
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Notifications;
use App\Album;
use App\Mail\MailableBase;
use App\Mail\PhotoCommentApproved as PhotoCommentApprovedMailable;
use App\Photo;
use App\PhotoComment;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class PhotoCommentApproved extends Notification
{
use Queueable;
use DatabaseEmailNotification;
private $album;
private $comment;
private $photo;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Album $album, Photo $photo, PhotoComment $comment)
{
$this->album = $album;
$this->photo = $photo;
$this->comment = $comment;
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage|MailableBase
*/
public function toMail($notifiable)
{
$mailable = new PhotoCommentApprovedMailable($notifiable, $this->album, $this->photo, $this->comment);
$this->setPropertiesOnMailable($mailable, $notifiable);
return $mailable;
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Notifications;
use App\Album;
use App\Mail\MailableBase;
use App\Mail\PhotoCommentApprovedUser as PhotoCommentApprovedUserMailable;
use App\Photo;
use App\PhotoComment;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class PhotoCommentApprovedUser extends Notification
{
use Queueable;
use DatabaseEmailNotification;
private $album;
private $comment;
private $photo;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Album $album, Photo $photo, PhotoComment $comment)
{
$this->album = $album;
$this->photo = $photo;
$this->comment = $comment;
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage|MailableBase
*/
public function toMail($notifiable)
{
$mailable = new PhotoCommentApprovedUserMailable($notifiable, $this->album, $this->photo, $this->comment);
$this->setPropertiesOnMailable($mailable, $notifiable);
return $mailable;
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Notifications;
use App\Album;
use App\Mail\MailableBase;
use App\Mail\PhotoCommentRepliedTo as PhotoCommentRepliedToMailable;
use App\Photo;
use App\PhotoComment;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class PhotoCommentRepliedTo extends Notification
{
use Queueable;
use DatabaseEmailNotification;
private $album;
private $comment;
private $photo;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Album $album, Photo $photo, PhotoComment $comment)
{
$this->album = $album;
$this->photo = $photo;
$this->comment = $comment;
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage|MailableBase
*/
public function toMail($notifiable)
{
$mailable = new PhotoCommentRepliedToMailable($notifiable, $this->album, $this->photo, $this->comment);
$this->setPropertiesOnMailable($mailable, $notifiable);
return $mailable;
}
}