Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/Mail/NewReplyEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion app/Notifications/NewReplyNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
8 changes: 6 additions & 2 deletions resources/views/emails/new_reply.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 35 additions & 0 deletions tests/Integration/Mail/NewReplyEmailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use App\Jobs\BanUser;
use App\Mail\NewReplyEmail;
use App\Models\Reply;
use App\Models\Subscription;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

uses(TestCase::class);
uses(DatabaseMigrations::class);

it('contains a note about solutions when the receiver is the thread author', function () {
$reply = Reply::factory()->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.');
});