WIP: Comment reply

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-02-10 09:35:26 +01:00
parent 8457f2f6c2
commit 07fd562a55
4 changed files with 117 additions and 0 deletions

View File

@@ -122,6 +122,9 @@ return [
['name' => 'attachment_api#delete', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/attachments/{attachmentId}', 'verb' => 'DELETE'],
['name' => 'attachment_api#restore', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/attachments/{attachmentId}/restore', 'verb' => 'PUT'],
['name' => 'comments_api#list', 'url' => '/api/v1.0/boards/{boardId}/stacks/{stackId}/cards/{cardId}/comments', 'verb' => 'GET'],
['name' => 'board_api#preflighted_cors', 'url' => '/api/v1.0/{path}','verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
]
];

1
img/reply.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16"><path d="M15 15s-.4-7.8-7-10V1L1 8l7 7v-4c5.1 0 7 4 7 4z"/></svg>

After

Width:  |  Height:  |  Size: 128 B

View File

@@ -0,0 +1,109 @@
<?php
/**
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Controller;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Comments\NotFoundException;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserManager;
class CommentsApiController extends ApiController {
/** @var ICommentsManager */
private $commentsManager;
/** @var IUserManager */
private $userManager;
/** @var ILogger */
private $logger;
public function __construct(
$appName, IRequest $request, $corsMethods = 'PUT, POST, GET, DELETE, PATCH', $corsAllowedHeaders = 'Authorization, Content-Type, Accept', $corsMaxAge = 1728000,
ICommentsManager $commentsManager,
IUserManager $userManager,
ILogger $logger
) {
parent::__construct($appName, $request, $corsMethods, $corsAllowedHeaders, $corsMaxAge);
$this->commentsManager = $commentsManager;
$this->userManager = $userManager;
$this->logger = $logger;
}
/**
* @NoAdminRequired
* @CORS
* @NoCSRFRequired
*/
public function list(int $cardId, $limit = 20, $offset = 0): JSONResponse {
$comments = $this->commentsManager->getForObject('deckCard', $cardId, $limit, $offset);
$result = [];
foreach ($comments as $comment) {
$formattedComment = $this->formatComment($comment);
try {
if ($comment->getParentId() !== '0' && $replyTo = $this->commentsManager->get($comment->getParentId())) {
$formattedComment['replyTo'] = $this->formatComment($replyTo);
}
} catch (NotFoundException $e) {
}
$result[] = $formattedComment;
}
return new JSONResponse($result);
}
private function formatComment(IComment $comment): array {
$user = $this->userManager->get($comment->getActorId());
$actorDisplayName = $user !== null ? $user->getDisplayName() : $comment->getActorId();
return [
'id' => $comment->getId(),
'message' => $comment->getMessage(),
'actorId' => $comment->getActorId(),
'actorType' => $comment->getActorType(),
'actorDisplayName' => $actorDisplayName,
'mentions' => array_map(function($mention) {
try {
$displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']);
} catch (\OutOfBoundsException $e) {
$this->logger->logException($e);
// No displayname, upon client's discretion what to display.
$displayName = '';
}
return [
'mentionId' => $mention['id'],
'mentionType' => $mention['type'],
'mentionDisplayName' => $displayName
];
}, $comment->getMentions()),
];
}
}

View File

@@ -32,6 +32,10 @@ export class CommentApi {
}
async loadComments({ cardId, limit, offset }) {
const api = await axios.get(OC.generateUrl(`/apps/deck/api/v1.0/boards/0/stacks/0/cards/${cardId}/comments`), {
headers: {'OCS-APIRequest': 'true'}
})
return api.data
const response = await axios({
method: 'REPORT',
url: this.url(`${cardId}`),