#4: A notification is now sent to the original poster when a reply is posted to their comment. Removed the "edit comment" link as this functionality doesn't (and won't) exist.

This commit is contained in:
Andy Heathershaw 2018-10-05 23:35:01 +01:00
parent 38e24cc4d6
commit 2c0595bb98
8 changed files with 195 additions and 7 deletions

View File

@ -2,11 +2,18 @@
namespace App\Http\Controllers\Admin;
use App\Album;
use App\Facade\Theme;
use App\Facade\UserConfig;
use App\Http\Controllers\Controller;
use App\Mail\PhotoCommentApproved;
use App\Mail\PhotoCommentApprovedUser;
use App\Mail\PhotoCommentRepliedTo;
use App\Photo;
use App\PhotoComment;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\View;
class PhotoCommentController extends Controller
@ -47,6 +54,12 @@ class PhotoCommentController extends Controller
/** @var PhotoComment $comment */
foreach ($comments as $comment)
{
if ($comment->isApproved())
{
// Don't make changes if already approved
continue;
}
// Mark as approved
$comment->approved_at = new \DateTime();
$comment->approved_user_id = $this->getUser()->id;
@ -55,8 +68,15 @@ class PhotoCommentController extends Controller
$comment->rejected_at = null;
$comment->rejected_user_id = null;
// Send the notification e-mail to the owner
$comment->save();
$commentsActioned++;
// Send e-mail notification
$photo = $comment->photo;
$album = $photo->album;
$this->notifyAlbumOwnerAndPoster($album, $photo, $comment);
}
$request->session()->flash('success', trans_choice('admin.bulk_comments_approved', $commentsActioned, ['number' => $commentsActioned]));
@ -66,6 +86,12 @@ class PhotoCommentController extends Controller
/** @var PhotoComment $comment */
foreach ($comments as $comment)
{
if ($comment->isRejected())
{
// Don't make changes if already rejected
continue;
}
// Mark as rejected
$comment->rejected_at = new \DateTime();
$comment->rejected_user_id = $this->getUser()->id;
@ -157,6 +183,12 @@ class PhotoCommentController extends Controller
$comment = $this->loadCommentByID($id);
if ($comment->isApproved())
{
// Comment has already been approved
return redirect(route('comments.index'));
}
// Mark as approved
$comment->approved_at = new \DateTime();
$comment->approved_user_id = $this->getUser()->id;
@ -171,6 +203,11 @@ class PhotoCommentController extends Controller
'author_name' => $comment->authorDisplayName()
]));
// Send e-mail notification
$photo = $comment->photo;
$album = $photo->album;
$this->notifyAlbumOwnerAndPoster($album, $photo, $comment);
return redirect(route('comments.index'));
}
@ -180,6 +217,12 @@ class PhotoCommentController extends Controller
$comment = $this->loadCommentByID($id);
if ($comment->isRejected())
{
// Comment has already been rejected
return redirect(route('comments.index'));
}
// Mark as rejected
$comment->rejected_at = new \DateTime();
$comment->rejected_user_id = $this->getUser()->id;
@ -292,4 +335,41 @@ class PhotoCommentController extends Controller
return $comment;
}
/**
* Sends an e-mail notification to an album's owned that a comment has been posted/approved.
* @param Album $album
* @param Photo $photo
* @param PhotoComment $comment
*/
private function notifyAlbumOwnerAndPoster(Album $album, Photo $photo, PhotoComment $comment)
{
$owner = $album->user;
Mail::to($owner)->send(new PhotoCommentApproved($owner, $album, $photo, $comment));
// Also send a notification to the comment poster
$poster = new User();
$poster->name = $comment->authorDisplayName();
$poster->email = $comment->authorEmail();
Mail::to($poster)->send(new PhotoCommentApprovedUser($poster, $album, $photo, $comment));
// Send notification to the parent comment owner (if this is a reply)
if (!is_null($comment->parent_comment_id))
{
$parentComment = $this->loadCommentByID($comment->parent_comment_id);
if (is_null($parentComment))
{
return;
}
$parentPoster = new User();
$parentPoster->name = $parentComment->authorDisplayName();
$parentPoster->email = $parentComment->authorEmail();
Mail::to($parentPoster)->send(new PhotoCommentRepliedTo($parentPoster, $album, $photo, $comment));
}
}
}

View File

@ -54,7 +54,7 @@ class PhotoCommentController extends Controller
$comment->approved_user_id = $this->getUser()->id;
$comment->save();
$this->notifyAlbumOwner($album, $photo, $comment);
$this->notifyAlbumOwnerAndPoster($album, $photo, $comment);
$request->getSession()->flash('success', trans('gallery.photo_comment_approved_successfully'));
}
else if ($request->has('reject'))
@ -191,7 +191,7 @@ class PhotoCommentController extends Controller
}
else
{
$this->notifyAlbumOwner($album, $photo, $comment);
$this->notifyAlbumOwnerAndPoster($album, $photo, $comment);
$request->getSession()->flash('success', trans('gallery.photo_comment_posted_successfully'));
}
@ -281,16 +281,35 @@ class PhotoCommentController extends Controller
* @param Photo $photo
* @param PhotoComment $comment
*/
private function notifyAlbumOwner(Album $album, Photo $photo, PhotoComment $comment)
private function notifyAlbumOwnerAndPoster(Album $album, Photo $photo, PhotoComment $comment)
{
$owner = $album->user;
Mail::to($owner)->send(new PhotoCommentApproved($owner, $album, $photo, $comment));
// Also send a notification to the comment poster
$poster = new User();
$poster->name = $comment->authorDisplayName();
$poster->email = $comment->authorEmail();
Mail::to($owner)->send(new PhotoCommentApproved($owner, $album, $photo, $comment));
Mail::to($poster)->send(new PhotoCommentApprovedUser($poster, $album, $photo, $comment));
// Send notification to the parent comment owner (if this is a reply)
if (!is_null($comment->parent_comment_id))
{
$parentComment = $this->loadCommentByID($comment->parent_comment_id);
if (is_null($parentComment))
{
return;
}
$parentPoster = new User();
$parentPoster->name = $parentComment->authorDisplayName();
$parentPoster->email = $parentComment->authorEmail();
Mail::to($parentPoster)->send(new PhotoCommentRepliedTo($parentPoster, $album, $photo, $comment));
}
}
private function stripDisallowedHtmlTags($commentText)

View File

@ -0,0 +1,60 @@
<?php
namespace App\Mail;
use App\Album;
use App\Facade\Theme;
use App\Photo;
use App\PhotoComment;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
/**
* E-mail notification to the poster of a comment that is sent when it has been approved.
* @package App\Mail
*/
class PhotoCommentRepliedTo extends Mailable
{
use Queueable, SerializesModels;
private $album;
private $comment;
private $photo;
private $user;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(User $user, Album $album, Photo $photo, PhotoComment $comment)
{
$this->user = $user;
$this->album = $album;
$this->photo = $photo;
$this->comment = $comment;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$subject = trans('email.photo_comment_replied_to_subject', ['album_name' => $this->album->name]);
return $this
->subject($subject)
->markdown(Theme::viewName('email.photo_comment_replied_to'))
->with([
'album' => $this->album,
'comment' => $this->comment,
'photo' => $this->photo,
'subject' => $subject,
'user' => $this->user
]);
}
}

View File

@ -25,5 +25,9 @@ return [
'photo_comment_approved_user_comment_label' => 'Comments:',
'photo_comment_approved_user_p1' => 'Your comment has been successfully posted in the :album_name album.',
'photo_comment_approved_user_p2' => 'Click the button below to view the photo\'s page to see your comment.',
'photo_comment_approved_user_subject' => 'Your comment was posted in :album_name'
'photo_comment_approved_user_subject' => 'Your comment was posted in :album_name',
'photo_comment_replied_to_comment_label' => 'Comments:',
'photo_comment_replied_to_p1' => 'A reply to your comment has been posted in the :album_name album.',
'photo_comment_replied_to_p2' => 'Click the button below to view the photo\'s page to see the reply to your comment.',
'photo_comment_replied_to_subject' => 'A reply to your comment was posted in :album_name'
];

View File

@ -40,6 +40,7 @@ return [
'parent_album_placeholder' => 'None (top-level album)',
'password_label' => 'Password:',
'password_confirm_label' => 'Confirm password:',
'photo_comment_email_help' => 'We\'ll only use this to send you notifications about your comment. It won\'t be published.',
'photo_comment_reply_action' => 'Post reply',
'photo_comment_submit_action' => 'Post comment',
'photo_comment_text_label' => 'Your message/comments:',

View File

@ -45,7 +45,8 @@
</td>
<td>
<p>
<a href="{{ route('comments.edit', ['id' => $comment->id]) }}"><span style="font-size: 1.3em;">{{ $comment->name }}</span></a>
{{-- TODO: edit comments <a href="{{ route('comments.edit', ['id' => $comment->id]) }}"><span style="font-size: 1.3em;">{{ $comment->name }}</span></a> --}}
<span style="font-size: 1.3em;">{{ $comment->name }}</span>
<br/>
<span class="text-muted" style="font-size: smaller;">{{ trans('admin.comment_summary', ['album_name' => $comment->photo->album->name, 'photo_name' => $comment->photo->name, 'comment_date' => date(UserConfig::get('date_format'), strtotime($comment->created_at))]) }}</span>

View File

@ -0,0 +1,22 @@
@component('mail::message')
@lang('email.generic_intro', ['user_name' => $user->name])
@lang('email.photo_comment_replied_to_p1', ['album_name' => $album->name])
@lang('email.photo_comment_replied_to_p2')
@lang('email.photo_comment_replied_to_comment_label')
{!! $comment->comment !!}
@component('mail::button', ['url' => $photo->url(), 'color' => 'blue'])
@lang('forms.view_photo_comment_action')
@endcomponent
@lang('email.generic_regards')<br/>
{{ UserConfig::get('app_name') }}<br/>
<a href="{{ route('home') }}">{{ route('home') }}</a>
@endcomponent

View File

@ -3,7 +3,7 @@ $is_reply = isset($reply_comment);
$is_known_user = !is_null(Auth::user())
@endphp
{{-- Show a previous of the comment we're replying to --}}
{{-- Show a preview of the comment we're replying to --}}
@if ($is_reply)
<div class="mb-3">
@include (Theme::viewName('partials.photo_single_comment'), ['comment' => $reply_comment, 'is_reply' => true])
@ -31,6 +31,7 @@ $is_known_user = !is_null(Auth::user())
<div class="form-group">
<label for="commentor-email">@lang('forms.email_label')</label>
<input type="text" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" id="commentor-email" name="email" value="{{ old('email', ($is_known_user ? Auth::user()->email : '')) }}" placeholder="@lang('forms.email_placeholder')"{{ $is_known_user ? ' readonly="readonly"' : '' }}//>
<small class="form-text text-muted">@lang('forms.photo_comment_email_help')</small>
@if ($errors->has('email'))
<div class="invalid-feedback">