Commit fcecbe1c authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(comments): add comment view partials for public pages

parent 0c187ef7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -426,6 +426,14 @@ $routes->group(
                                    'filter' => 'permission:podcast-manage_publications',
                                ]
                            );
                            $routes->post(
                                '(:uuid)/reply',
                                'EpisodeController::attemptCommentReply/$1/$2/$3',
                                [
                                    'as' => 'comment-attempt-reply',
                                    'filter' => 'permission:podcast-manage_publications',
                                ]
                            );
                            $routes->post(
                                'delete',
                                'EpisodeController::attemptCommentDelete/$1/$2',
+41 −0
Original line number Diff line number Diff line
@@ -821,4 +821,45 @@ class EpisodeController extends BaseController
        // Comment has been successfully created
        return redirect()->back();
    }

    public function attemptCommentReply(string $commentId): RedirectResponse
    {
        // var_dump($commentId);
        // die();

        $rules = [
            'message' => 'required|max_length[500]',
        ];

        if (! $this->validate($rules)) {
            return redirect()
                ->back()
                ->withInput()
                ->with('errors', $this->validator->getErrors());
        }

        $message = $this->request->getPost('message');

        $newReply = new EpisodeComment([
            'actor_id' => interact_as_actor_id(),
            'episode_id' => $this->episode->id,
            'message' => $message,
            'in_reply_to_id' => $commentId,
            'created_at' => new Time('now'),
            'created_by' => user_id(),
        ]);

        $commentModel = new EpisodeCommentModel();
        if (
            ! $commentModel->addComment($newReply, true)
        ) {
            return redirect()
                ->back()
                ->withInput()
                ->with('errors', $commentModel->errors());
        }

        // Reply has been successfully created
        return redirect()->back();
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -170,4 +170,12 @@ class EpisodeCommentController extends BaseController

        return redirect()->back();
    }

    public function attemptReply(): RedirectResponse
    {
        model('LikeModel')
            ->toggleLike(interact_as_actor(), $this->comment);

        return redirect()->back();
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -118,6 +118,20 @@ class EpisodeComment extends UuidEntity
        return $this->replies;
    }

    public function getReplyToComment(): ?self
    {
        if ($this->in_reply_to_id === null) {
            throw new RuntimeException('Comment is not a reply.');
        }

        if ($this->reply_to_comment === null) {
            $this->reply_to_comment = model('EpisodeCommentModel', false)
                ->getCommentById($this->in_reply_to_id);
        }

        return $this->reply_to_comment;
    }

    public function setMessage(string $message): static
    {
        helper('activitypub');
+10 −0
Original line number Diff line number Diff line
@@ -9,12 +9,22 @@ declare(strict_types=1);
 */

return [
    'title' => "{actorDisplayName}'s comment for {episodeTitle}",
    'back_to_episode' => 'Back to {episodeTitle}',
    'form' => [
        'episode_message_placeholder' => 'Write a comment...',
        'reply_to_placeholder' => 'Reply to @{actorUsername}',
        'submit' => 'Send!',
        'submit_reply' => 'Reply',
    ],
    'likes' => '{numberOfLikes, plural,
        one {# like}
        other {# likes}
    }',
    'replies' => '{numberOfReplies, plural,
        one {# reply}
        other {# replies}
    }',
    'like' => 'Like',
    'reply' => 'Reply',
    'view_replies' => 'View replies ({numberOfReplies})',
Loading