X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Fapi%2Fvideos%2Fcomment.ts;h=a95392543e1bce89b8b7a608b0460cca57e24e11;hb=b4055e1c23eeefb0c8a85a77f312b2827d98f483;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..a95392543 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,18 @@ 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.wrapPromise( + VideoCommentModel.listThreadsForApi(apiOptions), + 'filter:api.video-threads.list.result' + ) } else { resultList = { total: 0, @@ -94,7 +106,16 @@ 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: user + }, 'filter:api.video-thread-comments.list.params') + + resultList = await Hooks.wrapPromise( + VideoCommentModel.listThreadCommentsForApi(apiOptions), + 'filter:api.video-thread-comments.list.result' + ) } else { resultList = { total: 0, @@ -122,6 +143,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 +167,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 +179,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() }