laravelista / comments

Native comments for your Laravel application.
MIT License
745 stars 144 forks source link

Reply to Self? #106

Closed preimpression closed 4 years ago

preimpression commented 4 years ago

How might I allow users to reply to themselves?

For instance, in my website I want to allow users to store information in their comments if they so desire, so that they can link to specific comments to share with other users. Just requiring them to edit the comment wouldn't be effective.

Comment: "Resources"

(On another note, permalinking individual comments should also be added)

preimpression commented 4 years ago

(Title changed because I thought I had figured out how to allow replying to self and wanted to recycle the issue, but then realized I hadn't actually fixed anything.)

mabasic commented 4 years ago

You could change the guard for comments reply. See config reply-to-comment guard. Just set it to return true.

P.S. Open a new issue for permalinkinh to comments or send a PR. I'm willing to implement this feature.

preimpression commented 4 years ago

We got it to work - thanks!

[and gotcha, did so!: #110 ]

hondaman900 commented 4 years ago

I'm doing the same, but just opening the permission guard treats the reply when from the same user like a new comment, and doesn't indent as a reply. I'm struggling to find where the code indents a reply so that I can indent a user's reply to their own comment. Any suggestions?

hondaman900 commented 4 years ago

I found a hack solution by adding list HTML into the _comment.blade.php view as follows:

        {{-- Recursion for children --}}
        @if($grouped_comments->has($comment->getKey()))
           <ul style="list-style: none;">
         @foreach($grouped_comments[$comment->getKey()] as $child)
            <li> 
                @include('comments::_comment', [
                    'comment' => $child,
                    'reply' => true,
                    'grouped_comments' => $grouped_comments
                ])
                </li>
            @endforeach
            </ul>
        @endif

Hope this helps someone else.

ScuffedNewt commented 4 years ago

@hondaman900 hi! the solution is much simpler; in the file CommentPolicy, simply change

 public function reply($user, Comment $comment) : bool
    {
        return $user->getKey() != $comment->commenter_id;
    }
}

to

 public function reply($user, Comment $comment) : bool
    {
        return $user->getKey();
    }
}

or

 public function reply($user, Comment $comment) : bool
    {
        return true;
    }
}
hondaman900 commented 4 years ago

Thanks Ne-wt, I reversed my changes and tried that, but no difference to the indenting. Went back to my markup hack for now.