From e3a404a3eaaef48553006453cb151e8de4c57fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sat, 13 Jun 2020 13:11:41 +0200 Subject: [PATCH] Expose parentId in formatted comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/CommentService.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/Service/CommentService.php b/lib/Service/CommentService.php index 8234321a3..c389a9ad2 100644 --- a/lib/Service/CommentService.php +++ b/lib/Service/CommentService.php @@ -114,7 +114,7 @@ class CommentService { $comment->setVerb('comment'); $comment->setParentId($replyTo); $this->commentsManager->save($comment); - return new DataResponse($this->formatComment($comment)); + return new DataResponse($this->formatComment($comment, true)); } catch (\InvalidArgumentException $e) { throw new BadRequestException('Invalid input values'); } catch (MessageTooLongException $e) { @@ -177,13 +177,13 @@ class CommentService { return new DataResponse([]); } - private function formatComment(IComment $comment): array { + private function formatComment(IComment $comment, $addReplyTo = false): array { $user = $this->userManager->get($comment->getActorId()); $actorDisplayName = $user !== null ? $user->getDisplayName() : $comment->getActorId(); - return [ - 'id' => $comment->getId(), - 'objectId' => $comment->getObjectId(), + $formattedComment = [ + 'id' => (int)$comment->getId(), + 'objectId' => (int)$comment->getObjectId(), 'message' => $comment->getMessage(), 'actorId' => $comment->getActorId(), 'actorType' => $comment->getActorType(), @@ -205,5 +205,13 @@ class CommentService { ]; }, $comment->getMentions()), ]; + + try { + if ($addReplyTo && $comment->getParentId() !== '0' && $replyTo = $this->commentsManager->get($comment->getParentId())) { + $formattedComment['replyTo'] = $this->formatComment($replyTo); + } + } catch (CommentNotFoundException $e) { + } + return $formattedComment; } }