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()
let resultList: ResultList<VideoCommentModel>
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,
let resultList: ResultList<VideoCommentModel>
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,
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()
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()
}
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()
}