aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/comment.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-18 14:28:37 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commitb4055e1c23eeefb0c8a85a77f312b2827d98f483 (patch)
tree51b6b04c1ad10897047817d2eaaa037d1331fa6a /server/controllers/api/videos/comment.ts
parent66e001c848c009412c65cbce41be344d8985fd83 (diff)
downloadPeerTube-b4055e1c23eeefb0c8a85a77f312b2827d98f483.tar.gz
PeerTube-b4055e1c23eeefb0c8a85a77f312b2827d98f483.tar.zst
PeerTube-b4055e1c23eeefb0c8a85a77f312b2827d98f483.zip
Add server hooks
Diffstat (limited to 'server/controllers/api/videos/comment.ts')
-rw-r--r--server/controllers/api/videos/comment.ts36
1 files changed, 30 insertions, 6 deletions
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'
26import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' 26import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
27import { AccountModel } from '../../../models/account/account' 27import { AccountModel } from '../../../models/account/account'
28import { Notifier } from '../../../lib/notifier' 28import { Notifier } from '../../../lib/notifier'
29import { Hooks } from '../../../lib/plugins/hooks'
29 30
30const auditLogger = auditLoggerFactory('comments') 31const auditLogger = auditLoggerFactory('comments')
31const videoCommentRouter = express.Router() 32const videoCommentRouter = express.Router()
@@ -76,7 +77,18 @@ async function listVideoThreads (req: express.Request, res: express.Response) {
76 let resultList: ResultList<VideoCommentModel> 77 let resultList: ResultList<VideoCommentModel>
77 78
78 if (video.commentsEnabled === true) { 79 if (video.commentsEnabled === true) {
79 resultList = await VideoCommentModel.listThreadsForApi(video.id, req.query.start, req.query.count, req.query.sort, user) 80 const apiOptions = await Hooks.wrapObject({
81 videoId: video.id,
82 start: req.query.start,
83 count: req.query.count,
84 sort: req.query.sort,
85 user: user
86 }, 'filter:api.video-threads.list.params')
87
88 resultList = await Hooks.wrapPromise(
89 VideoCommentModel.listThreadsForApi(apiOptions),
90 'filter:api.video-threads.list.result'
91 )
80 } else { 92 } else {
81 resultList = { 93 resultList = {
82 total: 0, 94 total: 0,
@@ -94,7 +106,16 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo
94 let resultList: ResultList<VideoCommentModel> 106 let resultList: ResultList<VideoCommentModel>
95 107
96 if (video.commentsEnabled === true) { 108 if (video.commentsEnabled === true) {
97 resultList = await VideoCommentModel.listThreadCommentsForApi(video.id, res.locals.videoCommentThread.id, user) 109 const apiOptions = await Hooks.wrapObject({
110 videoId: video.id,
111 threadId: res.locals.videoCommentThread.id,
112 user: user
113 }, 'filter:api.video-thread-comments.list.params')
114
115 resultList = await Hooks.wrapPromise(
116 VideoCommentModel.listThreadCommentsForApi(apiOptions),
117 'filter:api.video-thread-comments.list.result'
118 )
98 } else { 119 } else {
99 resultList = { 120 resultList = {
100 total: 0, 121 total: 0,
@@ -122,6 +143,8 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons
122 Notifier.Instance.notifyOnNewComment(comment) 143 Notifier.Instance.notifyOnNewComment(comment)
123 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) 144 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
124 145
146 Hooks.runAction('action:api.video-thread.created', { comment })
147
125 return res.json({ 148 return res.json({
126 comment: comment.toFormattedJSON() 149 comment: comment.toFormattedJSON()
127 }).end() 150 }).end()
@@ -144,6 +167,8 @@ async function addVideoCommentReply (req: express.Request, res: express.Response
144 Notifier.Instance.notifyOnNewComment(comment) 167 Notifier.Instance.notifyOnNewComment(comment)
145 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) 168 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
146 169
170 Hooks.runAction('action:api.video-comment-reply.created', { comment })
171
147 return res.json({ comment: comment.toFormattedJSON() }).end() 172 return res.json({ comment: comment.toFormattedJSON() }).end()
148} 173}
149 174
@@ -154,11 +179,10 @@ async function removeVideoComment (req: express.Request, res: express.Response)
154 await videoCommentInstance.destroy({ transaction: t }) 179 await videoCommentInstance.destroy({ transaction: t })
155 }) 180 })
156 181
157 auditLogger.delete( 182 auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON()))
158 getAuditIdFromRes(res),
159 new CommentAuditView(videoCommentInstance.toFormattedJSON())
160 )
161 logger.info('Video comment %d deleted.', videoCommentInstance.id) 183 logger.info('Video comment %d deleted.', videoCommentInstance.id)
162 184
185 Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstance })
186
163 return res.type('json').status(204).end() 187 return res.type('json').status(204).end()
164} 188}