|
|
@ -51,6 +51,7 @@ class CommentController extends SiteController { |
|
|
|
if (!res.locals.comment) { |
|
|
|
return next(new SiteError(404, 'Comment not found')); |
|
|
|
} |
|
|
|
res.locals.post = res.locals.comment.resource; |
|
|
|
return next(); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to populate commentId', { commentId, error }); |
|
|
@ -87,12 +88,24 @@ class CommentController extends SiteController { |
|
|
|
try { |
|
|
|
const displayList = this.createDisplayList('get-replies'); |
|
|
|
|
|
|
|
if (req.query.buttonId) { |
|
|
|
displayList.removeElement(`li.dtp-load-more[data-button-id="${req.query.buttonId}"]`); |
|
|
|
} |
|
|
|
|
|
|
|
Object.assign(res.locals, req.app.locals); |
|
|
|
|
|
|
|
res.locals.pagination = this.getPaginationParameters(req, 20); |
|
|
|
res.locals.countPerPage = parseInt(req.query.cpp || "20", 10); |
|
|
|
if (res.locals.countPerPage < 1) { |
|
|
|
res.locals.countPerPage = 1; |
|
|
|
} |
|
|
|
if (res.locals.countPerPage > 20) { |
|
|
|
res.locals.countPerPage = 20; |
|
|
|
} |
|
|
|
|
|
|
|
res.locals.pagination = this.getPaginationParameters(req, res.locals.countPerPage); |
|
|
|
res.locals.comments = await commentService.getReplies(res.locals.comment, res.locals.pagination); |
|
|
|
|
|
|
|
const html = await commentService.renderTemplate('commentList', res.locals); |
|
|
|
const html = await commentService.renderTemplate('replyList', res.locals); |
|
|
|
|
|
|
|
const replyList = `ul.dtp-reply-list[data-comment-id="${res.locals.comment._id}"]`; |
|
|
|
displayList.addElement(replyList, 'beforeEnd', html); |
|
|
@ -102,9 +115,9 @@ class CommentController extends SiteController { |
|
|
|
|
|
|
|
res.status(200).json({ success: true, displayList }); |
|
|
|
} catch (error) { |
|
|
|
this.log.error('failed to display comment replies', { error }); |
|
|
|
res.status(error.statusCode || 500).json({ success: false, message: error.message }); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
async deleteComment (req, res) { |
|
|
|