X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fcomment.ts;h=39d521f5f9ea6966a04bb21593fba342db138937;hb=fd2ddcae8ff4eb10bf7168ac3c8801f06b37627f;hp=176ee8bd4dd326e168b4f6a85b29c7558fa8d292;hpb=97567dd81f508dd6295ac4d73d849aa2ce0a6549;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 176ee8bd4..39d521f5f 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts @@ -26,6 +26,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment' import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' import { AccountModel } from '../../../models/account/account' import { Notifier } from '../../../lib/notifier' +import { Hooks } from '../../../lib/plugins/hooks' const auditLogger = auditLoggerFactory('comments') const videoCommentRouter = express.Router() @@ -76,7 +77,19 @@ async function listVideoThreads (req: express.Request, res: express.Response) { let resultList: ResultList if (video.commentsEnabled === true) { - resultList = await VideoCommentModel.listThreadsForApi(video.id, req.query.start, req.query.count, req.query.sort, user) + const apiOptions = await Hooks.wrapObject({ + videoId: video.id, + start: req.query.start, + count: req.query.count, + sort: req.query.sort, + user: user + }, 'filter:api.video-threads.list.params') + + resultList = await Hooks.wrapPromiseFun( + VideoCommentModel.listThreadsForApi, + apiOptions, + 'filter:api.video-threads.list.result' + ) } else { resultList = { total: 0, @@ -94,7 +107,17 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo let resultList: ResultList if (video.commentsEnabled === true) { - resultList = await VideoCommentModel.listThreadCommentsForApi(video.id, res.locals.videoCommentThread.id, user) + const apiOptions = await Hooks.wrapObject({ + videoId: video.id, + threadId: res.locals.videoCommentThread.id, + user + }, 'filter:api.video-thread-comments.list.params') + + resultList = await Hooks.wrapPromiseFun( + VideoCommentModel.listThreadCommentsForApi, + apiOptions, + 'filter:api.video-thread-comments.list.result' + ) } else { resultList = { total: 0, @@ -122,6 +145,8 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons Notifier.Instance.notifyOnNewComment(comment) auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) + Hooks.runAction('action:api.video-thread.created', { comment }) + return res.json({ comment: comment.toFormattedJSON() }).end() @@ -144,6 +169,8 @@ async function addVideoCommentReply (req: express.Request, res: express.Response Notifier.Instance.notifyOnNewComment(comment) auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) + Hooks.runAction('action:api.video-comment-reply.created', { comment }) + return res.json({ comment: comment.toFormattedJSON() }).end() } @@ -154,11 +181,10 @@ async function removeVideoComment (req: express.Request, res: express.Response) await videoCommentInstance.destroy({ transaction: t }) }) - auditLogger.delete( - getAuditIdFromRes(res), - new CommentAuditView(videoCommentInstance.toFormattedJSON()) - ) + auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) logger.info('Video comment %d deleted.', videoCommentInstance.id) + Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstance }) + return res.type('json').status(204).end() }