Expose parentId in formatted comments

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-06-13 13:11:41 +02:00
parent f808c0551d
commit e3a404a3ea

View File

@@ -114,7 +114,7 @@ class CommentService {
$comment->setVerb('comment'); $comment->setVerb('comment');
$comment->setParentId($replyTo); $comment->setParentId($replyTo);
$this->commentsManager->save($comment); $this->commentsManager->save($comment);
return new DataResponse($this->formatComment($comment)); return new DataResponse($this->formatComment($comment, true));
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
throw new BadRequestException('Invalid input values'); throw new BadRequestException('Invalid input values');
} catch (MessageTooLongException $e) { } catch (MessageTooLongException $e) {
@@ -177,13 +177,13 @@ class CommentService {
return new DataResponse([]); return new DataResponse([]);
} }
private function formatComment(IComment $comment): array { private function formatComment(IComment $comment, $addReplyTo = false): array {
$user = $this->userManager->get($comment->getActorId()); $user = $this->userManager->get($comment->getActorId());
$actorDisplayName = $user !== null ? $user->getDisplayName() : $comment->getActorId(); $actorDisplayName = $user !== null ? $user->getDisplayName() : $comment->getActorId();
return [ $formattedComment = [
'id' => $comment->getId(), 'id' => (int)$comment->getId(),
'objectId' => $comment->getObjectId(), 'objectId' => (int)$comment->getObjectId(),
'message' => $comment->getMessage(), 'message' => $comment->getMessage(),
'actorId' => $comment->getActorId(), 'actorId' => $comment->getActorId(),
'actorType' => $comment->getActorType(), 'actorType' => $comment->getActorType(),
@@ -205,5 +205,13 @@ class CommentService {
]; ];
}, $comment->getMentions()), }, $comment->getMentions()),
]; ];
try {
if ($addReplyTo && $comment->getParentId() !== '0' && $replyTo = $this->commentsManager->get($comment->getParentId())) {
$formattedComment['replyTo'] = $this->formatComment($replyTo);
}
} catch (CommentNotFoundException $e) {
}
return $formattedComment;
} }
} }