refactor: rename for Laravel conventions and better DX

- Rename IsCommenter trait to CanComment, Commenter interface to Commentator
- Move models to Models/ namespace (Comment, Reaction, Attachment, Subscription)
- Rename user_type/user_id polymorphic columns to commenter_type/commenter_id
- Rename Config class to CommentsConfig, update config key tables->table_names
- Rename getCommentName() to getCommentDisplayName() on commentator models
- Add column_names config section for commenter morph customization
- Add table_names config with all 5 tables individually configurable
- Expand translation file with structured i18n groups
- Update all Blade views, Livewire components, events, listeners, and tests
This commit is contained in:
manukminasyan
2026-03-27 14:53:12 +04:00
parent 43b66f60f3
commit fd5bc5271b
62 changed files with 733 additions and 653 deletions

View File

@@ -1,12 +1,12 @@
<?php
use Illuminate\Support\Facades\Notification;
use Relaticle\Comments\Comment;
use Relaticle\Comments\CommentSubscription;
use Relaticle\Comments\Events\CommentCreated;
use Relaticle\Comments\Events\UserMentioned;
use Relaticle\Comments\Listeners\SendCommentRepliedNotification;
use Relaticle\Comments\Listeners\SendUserMentionedNotification;
use Relaticle\Comments\Models\Comment;
use Relaticle\Comments\Models\Subscription;
use Relaticle\Comments\Notifications\CommentRepliedNotification;
use Relaticle\Comments\Notifications\UserMentionedNotification;
use Relaticle\Comments\Tests\Models\Post;
@@ -19,21 +19,21 @@ it('sends CommentRepliedNotification to parent comment author when reply is crea
$replyAuthor = User::factory()->create();
$post = Post::factory()->create();
CommentSubscription::subscribe($post, $parentAuthor);
Subscription::subscribe($post, $parentAuthor);
$parentComment = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $parentAuthor->getKey(),
'user_type' => $parentAuthor->getMorphClass(),
'commenter_id' => $parentAuthor->getKey(),
'commenter_type' => $parentAuthor->getMorphClass(),
'body' => '<p>Parent comment</p>',
]);
$reply = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $replyAuthor->getKey(),
'user_type' => $replyAuthor->getMorphClass(),
'commenter_id' => $replyAuthor->getKey(),
'commenter_type' => $replyAuthor->getMorphClass(),
'parent_id' => $parentComment->id,
'body' => '<p>A reply</p>',
]);
@@ -51,13 +51,13 @@ it('does NOT send reply notification for top-level comments', function () {
$subscriber = User::factory()->create();
$post = Post::factory()->create();
CommentSubscription::subscribe($post, $subscriber);
Subscription::subscribe($post, $subscriber);
$comment = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $author->getKey(),
'user_type' => $author->getMorphClass(),
'commenter_id' => $author->getKey(),
'commenter_type' => $author->getMorphClass(),
'body' => '<p>Top-level comment</p>',
]);
@@ -73,21 +73,21 @@ it('does NOT send reply notification to the reply author', function () {
$user = User::factory()->create();
$post = Post::factory()->create();
CommentSubscription::subscribe($post, $user);
Subscription::subscribe($post, $user);
$parentComment = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $user->getKey(),
'user_type' => $user->getMorphClass(),
'commenter_id' => $user->getKey(),
'commenter_type' => $user->getMorphClass(),
'body' => '<p>My comment</p>',
]);
$reply = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $user->getKey(),
'user_type' => $user->getMorphClass(),
'commenter_id' => $user->getKey(),
'commenter_type' => $user->getMorphClass(),
'parent_id' => $parentComment->id,
'body' => '<p>My own reply</p>',
]);
@@ -108,8 +108,8 @@ it('sends UserMentionedNotification when a user is mentioned', function () {
$comment = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $author->getKey(),
'user_type' => $author->getMorphClass(),
'commenter_id' => $author->getKey(),
'commenter_type' => $author->getMorphClass(),
'body' => '<p>Hey @someone</p>',
]);
@@ -128,8 +128,8 @@ it('does NOT send mention notification to the comment author', function () {
$comment = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $author->getKey(),
'user_type' => $author->getMorphClass(),
'commenter_id' => $author->getKey(),
'commenter_type' => $author->getMorphClass(),
'body' => '<p>Hey @myself</p>',
]);
@@ -146,22 +146,22 @@ it('does NOT send reply notification to unsubscribed user', function () {
$unsubscribedUser = User::factory()->create();
$post = Post::factory()->create();
CommentSubscription::subscribe($post, $unsubscribedUser);
CommentSubscription::unsubscribe($post, $unsubscribedUser);
Subscription::subscribe($post, $unsubscribedUser);
Subscription::unsubscribe($post, $unsubscribedUser);
$parentComment = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $unsubscribedUser->getKey(),
'user_type' => $unsubscribedUser->getMorphClass(),
'commenter_id' => $unsubscribedUser->getKey(),
'commenter_type' => $unsubscribedUser->getMorphClass(),
'body' => '<p>Original</p>',
]);
$reply = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $author->getKey(),
'user_type' => $author->getMorphClass(),
'commenter_id' => $author->getKey(),
'commenter_type' => $author->getMorphClass(),
'parent_id' => $parentComment->id,
'body' => '<p>Reply</p>',
]);
@@ -178,20 +178,20 @@ it('auto-subscribes the comment author when creating a comment', function () {
$author = User::factory()->create();
$post = Post::factory()->create();
expect(CommentSubscription::isSubscribed($post, $author))->toBeFalse();
expect(Subscription::isSubscribed($post, $author))->toBeFalse();
$comment = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $author->getKey(),
'user_type' => $author->getMorphClass(),
'commenter_id' => $author->getKey(),
'commenter_type' => $author->getMorphClass(),
'body' => '<p>My comment</p>',
]);
$listener = new SendCommentRepliedNotification;
$listener->handle(new CommentCreated($comment));
expect(CommentSubscription::isSubscribed($post, $author))->toBeTrue();
expect(Subscription::isSubscribed($post, $author))->toBeTrue();
});
it('suppresses all notifications when notifications are disabled via config', function () {
@@ -203,21 +203,21 @@ it('suppresses all notifications when notifications are disabled via config', fu
$mentioned = User::factory()->create();
$post = Post::factory()->create();
CommentSubscription::subscribe($post, $subscriber);
Subscription::subscribe($post, $subscriber);
$parentComment = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $subscriber->getKey(),
'user_type' => $subscriber->getMorphClass(),
'commenter_id' => $subscriber->getKey(),
'commenter_type' => $subscriber->getMorphClass(),
'body' => '<p>Original</p>',
]);
$reply = Comment::factory()->create([
'commentable_id' => $post->id,
'commentable_type' => $post->getMorphClass(),
'user_id' => $author->getKey(),
'user_type' => $author->getMorphClass(),
'commenter_id' => $author->getKey(),
'commenter_type' => $author->getMorphClass(),
'parent_id' => $parentComment->id,
'body' => '<p>Reply</p>',
]);