From 83d57b489fcca7bdf444cb98a28bd67f2816ba55 Mon Sep 17 00:00:00 2001 From: faissaloux Date: Sun, 14 Nov 2021 13:47:23 +0100 Subject: [PATCH 1/3] new reply email cta --- app/Listeners/SendNewReplyNotification.php | 2 +- app/Mail/NewReplyEmail.php | 16 +++++++++++++++- app/Notifications/NewReplyNotification.php | 11 +++++++++-- resources/views/emails/new_reply.blade.php | 4 ++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/Listeners/SendNewReplyNotification.php b/app/Listeners/SendNewReplyNotification.php index f9bce9324..89a5b300b 100644 --- a/app/Listeners/SendNewReplyNotification.php +++ b/app/Listeners/SendNewReplyNotification.php @@ -17,7 +17,7 @@ public function handle(ReplyWasCreated $event): void foreach ($thread->subscriptions() as $subscription) { if ($this->replyAuthorDoesNotMatchSubscriber($event->reply->author(), $subscription)) { - $subscription->user()->notify(new NewReplyNotification($event->reply, $subscription)); + $subscription->user()->notify(new NewReplyNotification($thread, $event->reply, $subscription)); } } } diff --git a/app/Mail/NewReplyEmail.php b/app/Mail/NewReplyEmail.php index b5f50da06..37a2a4350 100644 --- a/app/Mail/NewReplyEmail.php +++ b/app/Mail/NewReplyEmail.php @@ -4,10 +4,17 @@ use App\Models\Reply; use App\Models\Subscription; +use App\Models\Thread; +use App\Models\User; use Illuminate\Mail\Mailable; final class NewReplyEmail extends Mailable { + /** + * @var \App\Models\Thread + */ + public $thread; + /** * @var \App\Models\Reply */ @@ -18,10 +25,17 @@ final class NewReplyEmail extends Mailable */ public $subscription; - public function __construct(Reply $reply, Subscription $subscription) + /** + * @var \App\Models\User + */ + public $user; + + public function __construct(Thread $thread, Reply $reply, Subscription $subscription, User $user) { + $this->thread = $thread; $this->reply = $reply; $this->subscription = $subscription; + $this->user = $user; } public function build() diff --git a/app/Notifications/NewReplyNotification.php b/app/Notifications/NewReplyNotification.php index b0c179f89..b57d96608 100644 --- a/app/Notifications/NewReplyNotification.php +++ b/app/Notifications/NewReplyNotification.php @@ -5,6 +5,7 @@ use App\Mail\NewReplyEmail; use App\Models\Reply; use App\Models\Subscription; +use App\Models\Thread; use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -14,6 +15,11 @@ final class NewReplyNotification extends Notification implements ShouldQueue { use Queueable; + /** + * @var \App\Models\Thread + */ + public $thread; + /** * @var \App\Models\Reply */ @@ -24,8 +30,9 @@ final class NewReplyNotification extends Notification implements ShouldQueue */ public $subscription; - public function __construct(Reply $reply, Subscription $subscription) + public function __construct(Thread $thread, Reply $reply, Subscription $subscription) { + $this->thread = $thread; $this->reply = $reply; $this->subscription = $subscription; } @@ -37,7 +44,7 @@ public function via(User $user) public function toMail(User $user) { - return (new NewReplyEmail($this->reply, $this->subscription)) + return (new NewReplyEmail($this->thread, $this->reply, $this->subscription, $user)) ->to($user->emailAddress(), $user->name()); } diff --git a/resources/views/emails/new_reply.blade.php b/resources/views/emails/new_reply.blade.php index 281b8d887..8d2f77744 100644 --- a/resources/views/emails/new_reply.blade.php +++ b/resources/views/emails/new_reply.blade.php @@ -6,6 +6,10 @@ {{ $reply->excerpt(200) }} @endcomponent +@if($thread->isAuthoredBy($user)) + Make sure to mark the correct reply as the solution when your question gets answered. +@endif + @component('mail::button', ['url' => route('thread', $reply->replyAble()->slug())]) View Thread @endcomponent From 4d45e32a0c9bba956e61805ac2e6d5545f18ae33 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Sun, 21 Nov 2021 11:40:33 +0100 Subject: [PATCH 2/3] wip --- app/Listeners/SendNewReplyNotification.php | 2 +- app/Mail/NewReplyEmail.php | 8 ++++---- app/Notifications/NewReplyNotification.php | 11 ++--------- resources/views/emails/new_reply.blade.php | 8 ++++---- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/app/Listeners/SendNewReplyNotification.php b/app/Listeners/SendNewReplyNotification.php index 89a5b300b..f9bce9324 100644 --- a/app/Listeners/SendNewReplyNotification.php +++ b/app/Listeners/SendNewReplyNotification.php @@ -17,7 +17,7 @@ public function handle(ReplyWasCreated $event): void foreach ($thread->subscriptions() as $subscription) { if ($this->replyAuthorDoesNotMatchSubscriber($event->reply->author(), $subscription)) { - $subscription->user()->notify(new NewReplyNotification($thread, $event->reply, $subscription)); + $subscription->user()->notify(new NewReplyNotification($event->reply, $subscription)); } } } diff --git a/app/Mail/NewReplyEmail.php b/app/Mail/NewReplyEmail.php index 37a2a4350..9a9af3773 100644 --- a/app/Mail/NewReplyEmail.php +++ b/app/Mail/NewReplyEmail.php @@ -28,14 +28,14 @@ final class NewReplyEmail extends Mailable /** * @var \App\Models\User */ - public $user; + public $receiver; - public function __construct(Thread $thread, Reply $reply, Subscription $subscription, User $user) + public function __construct(Reply $reply, Subscription $subscription, User $receiver) { - $this->thread = $thread; + $this->thread = $reply->replyAble(); $this->reply = $reply; $this->subscription = $subscription; - $this->user = $user; + $this->receiver = $receiver; } public function build() diff --git a/app/Notifications/NewReplyNotification.php b/app/Notifications/NewReplyNotification.php index b57d96608..5233a32d0 100644 --- a/app/Notifications/NewReplyNotification.php +++ b/app/Notifications/NewReplyNotification.php @@ -5,7 +5,6 @@ use App\Mail\NewReplyEmail; use App\Models\Reply; use App\Models\Subscription; -use App\Models\Thread; use App\Models\User; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -15,11 +14,6 @@ final class NewReplyNotification extends Notification implements ShouldQueue { use Queueable; - /** - * @var \App\Models\Thread - */ - public $thread; - /** * @var \App\Models\Reply */ @@ -30,9 +24,8 @@ final class NewReplyNotification extends Notification implements ShouldQueue */ public $subscription; - public function __construct(Thread $thread, Reply $reply, Subscription $subscription) + public function __construct(Reply $reply, Subscription $subscription) { - $this->thread = $thread; $this->reply = $reply; $this->subscription = $subscription; } @@ -44,7 +37,7 @@ public function via(User $user) public function toMail(User $user) { - return (new NewReplyEmail($this->thread, $this->reply, $this->subscription, $user)) + return (new NewReplyEmail($this->reply, $this->subscription, $user)) ->to($user->emailAddress(), $user->name()); } diff --git a/resources/views/emails/new_reply.blade.php b/resources/views/emails/new_reply.blade.php index 8d2f77744..7987847a8 100644 --- a/resources/views/emails/new_reply.blade.php +++ b/resources/views/emails/new_reply.blade.php @@ -6,8 +6,8 @@ {{ $reply->excerpt(200) }} @endcomponent -@if($thread->isAuthoredBy($user)) - Make sure to mark the correct reply as the solution when your question gets answered. +@if ($thread->isAuthoredBy($receiver)) +Please make sure to mark the correct reply as the solution when your question gets answered. @endif @component('mail::button', ['url' => route('thread', $reply->replyAble()->slug())]) @@ -15,8 +15,8 @@ @endcomponent @component('mail::subcopy') - You are receiving this because you are subscribed to this thread. - [Unsubscribe]({{ route('subscriptions.unsubscribe', $subscription->uuid()->toString()) }}) from this thread. +You are receiving this because you are subscribed to this thread. +[Unsubscribe]({{ route('subscriptions.unsubscribe', $subscription->uuid()->toString()) }}) from this thread. @endcomponent @endcomponent From 3600d59f780bf5cf26ed32499e347549a195e0f7 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Sun, 21 Nov 2021 12:00:26 +0100 Subject: [PATCH 3/3] wip --- tests/Integration/Mail/NewReplyEmailTest.php | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/Integration/Mail/NewReplyEmailTest.php diff --git a/tests/Integration/Mail/NewReplyEmailTest.php b/tests/Integration/Mail/NewReplyEmailTest.php new file mode 100644 index 000000000..28d1fb950 --- /dev/null +++ b/tests/Integration/Mail/NewReplyEmailTest.php @@ -0,0 +1,35 @@ +create(); + $thread = $reply->replyAble(); + $subscription = Subscription::factory()->create(['subscriptionable_id' => $thread->id]); + + $email = (new NewReplyEmail($reply, $subscription, $thread->author()))->render(); + + expect($email) + ->toContain('Please make sure to mark the correct reply as the solution when your question gets answered.'); +}); + +it('misses the note about solutions when the receiver is not the thread author', function () { + $reply = Reply::factory()->create(); + $thread = $reply->replyAble(); + $user = User::factory()->create(); + $subscription = Subscription::factory()->create(['subscriptionable_id' => $thread->id]); + + $email = (new NewReplyEmail($reply, $subscription, $user))->render(); + + expect($email)->not + ->toContain('Please make sure to mark the correct reply as the solution when your question gets answered.'); +});