diff --git a/app/Mail/NewReplyEmail.php b/app/Mail/NewReplyEmail.php index b5f50da06..9a9af3773 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 $receiver; + + public function __construct(Reply $reply, Subscription $subscription, User $receiver) { + $this->thread = $reply->replyAble(); $this->reply = $reply; $this->subscription = $subscription; + $this->receiver = $receiver; } public function build() diff --git a/app/Notifications/NewReplyNotification.php b/app/Notifications/NewReplyNotification.php index b0c179f89..5233a32d0 100644 --- a/app/Notifications/NewReplyNotification.php +++ b/app/Notifications/NewReplyNotification.php @@ -37,7 +37,7 @@ public function via(User $user) public function toMail(User $user) { - return (new NewReplyEmail($this->reply, $this->subscription)) + 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 281b8d887..7987847a8 100644 --- a/resources/views/emails/new_reply.blade.php +++ b/resources/views/emails/new_reply.blade.php @@ -6,13 +6,17 @@ {{ $reply->excerpt(200) }} @endcomponent +@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())]) View Thread @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 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.'); +});