diff --git a/app/Livewire/Comment.php b/app/Livewire/Comment.php index d06c7b7..6ecd5f9 100644 --- a/app/Livewire/Comment.php +++ b/app/Livewire/Comment.php @@ -4,8 +4,12 @@ namespace App\Livewire; use App\Models\User; +use App\Models\Episode; +use App\Notifications\CommentNotification; use Livewire\Component; + +use Illuminate\Support\Str; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\RateLimiter; @@ -75,6 +79,7 @@ class Comment extends Component public function postReply() { if (!($this->comment->depth() < 2)) { + $this->addError('replyState.body', "Too many sub comments."); return; } @@ -100,6 +105,22 @@ class Comment extends Component $reply->save(); + // Notify if Episode and if not the same user + if ($reply->commentable_type == Episode::class && $user->id !== $reply->parent->user->id) { + $episode = Episode::where('id', $reply->commentable_id) + ->firstOrFail(); + + $url = route('hentai.index', ['title' => $episode->slug]); + + $reply->parent->user->notify( + new CommentNotification( + "{$user->name} replied to your comment.", + Str::limit($reply->body, 50), + "{$url}#comment-{$reply->id}" + ) + ); + } + $this->replyState = [ 'body' => '' ];