diff options
Diffstat (limited to 'server/controllers/api/videos/comment.ts')
-rw-r--r-- | server/controllers/api/videos/comment.ts | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts index 4f2b4faee..70c1148ba 100644 --- a/server/controllers/api/videos/comment.ts +++ b/server/controllers/api/videos/comment.ts | |||
@@ -8,7 +8,7 @@ import { buildFormattedCommentTree, createVideoComment } from '../../../lib/vide | |||
8 | import { | 8 | import { |
9 | asyncMiddleware, | 9 | asyncMiddleware, |
10 | asyncRetryTransactionMiddleware, | 10 | asyncRetryTransactionMiddleware, |
11 | authenticate, | 11 | authenticate, optionalAuthenticate, |
12 | paginationValidator, | 12 | paginationValidator, |
13 | setDefaultPagination, | 13 | setDefaultPagination, |
14 | setDefaultSort | 14 | setDefaultSort |
@@ -26,6 +26,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment' | |||
26 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' | 26 | import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger' |
27 | import { AccountModel } from '../../../models/account/account' | 27 | import { AccountModel } from '../../../models/account/account' |
28 | import { UserModel } from '../../../models/account/user' | 28 | import { UserModel } from '../../../models/account/user' |
29 | import { Notifier } from '../../../lib/notifier' | ||
29 | 30 | ||
30 | const auditLogger = auditLoggerFactory('comments') | 31 | const auditLogger = auditLoggerFactory('comments') |
31 | const videoCommentRouter = express.Router() | 32 | const videoCommentRouter = express.Router() |
@@ -36,10 +37,12 @@ videoCommentRouter.get('/:videoId/comment-threads', | |||
36 | setDefaultSort, | 37 | setDefaultSort, |
37 | setDefaultPagination, | 38 | setDefaultPagination, |
38 | asyncMiddleware(listVideoCommentThreadsValidator), | 39 | asyncMiddleware(listVideoCommentThreadsValidator), |
40 | optionalAuthenticate, | ||
39 | asyncMiddleware(listVideoThreads) | 41 | asyncMiddleware(listVideoThreads) |
40 | ) | 42 | ) |
41 | videoCommentRouter.get('/:videoId/comment-threads/:threadId', | 43 | videoCommentRouter.get('/:videoId/comment-threads/:threadId', |
42 | asyncMiddleware(listVideoThreadCommentsValidator), | 44 | asyncMiddleware(listVideoThreadCommentsValidator), |
45 | optionalAuthenticate, | ||
43 | asyncMiddleware(listVideoThreadComments) | 46 | asyncMiddleware(listVideoThreadComments) |
44 | ) | 47 | ) |
45 | 48 | ||
@@ -69,10 +72,12 @@ export { | |||
69 | 72 | ||
70 | async function listVideoThreads (req: express.Request, res: express.Response, next: express.NextFunction) { | 73 | async function listVideoThreads (req: express.Request, res: express.Response, next: express.NextFunction) { |
71 | const video = res.locals.video as VideoModel | 74 | const video = res.locals.video as VideoModel |
75 | const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined | ||
76 | |||
72 | let resultList: ResultList<VideoCommentModel> | 77 | let resultList: ResultList<VideoCommentModel> |
73 | 78 | ||
74 | if (video.commentsEnabled === true) { | 79 | if (video.commentsEnabled === true) { |
75 | resultList = await VideoCommentModel.listThreadsForApi(video.id, req.query.start, req.query.count, req.query.sort) | 80 | resultList = await VideoCommentModel.listThreadsForApi(video.id, req.query.start, req.query.count, req.query.sort, user) |
76 | } else { | 81 | } else { |
77 | resultList = { | 82 | resultList = { |
78 | total: 0, | 83 | total: 0, |
@@ -85,10 +90,12 @@ async function listVideoThreads (req: express.Request, res: express.Response, ne | |||
85 | 90 | ||
86 | async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) { | 91 | async function listVideoThreadComments (req: express.Request, res: express.Response, next: express.NextFunction) { |
87 | const video = res.locals.video as VideoModel | 92 | const video = res.locals.video as VideoModel |
93 | const user: UserModel = res.locals.oauth ? res.locals.oauth.token.User : undefined | ||
94 | |||
88 | let resultList: ResultList<VideoCommentModel> | 95 | let resultList: ResultList<VideoCommentModel> |
89 | 96 | ||
90 | if (video.commentsEnabled === true) { | 97 | if (video.commentsEnabled === true) { |
91 | resultList = await VideoCommentModel.listThreadCommentsForApi(video.id, res.locals.videoCommentThread.id) | 98 | resultList = await VideoCommentModel.listThreadCommentsForApi(video.id, res.locals.videoCommentThread.id, user) |
92 | } else { | 99 | } else { |
93 | resultList = { | 100 | resultList = { |
94 | total: 0, | 101 | total: 0, |
@@ -113,6 +120,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons | |||
113 | }, t) | 120 | }, t) |
114 | }) | 121 | }) |
115 | 122 | ||
123 | Notifier.Instance.notifyOnNewComment(comment) | ||
116 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) | 124 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) |
117 | 125 | ||
118 | return res.json({ | 126 | return res.json({ |
@@ -134,6 +142,7 @@ async function addVideoCommentReply (req: express.Request, res: express.Response | |||
134 | }, t) | 142 | }, t) |
135 | }) | 143 | }) |
136 | 144 | ||
145 | Notifier.Instance.notifyOnNewComment(comment) | ||
137 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) | 146 | auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON())) |
138 | 147 | ||
139 | return res.json({ comment: comment.toFormattedJSON() }).end() | 148 | return res.json({ comment: comment.toFormattedJSON() }).end() |