aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/comment.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/videos/comment.ts')
-rw-r--r--server/controllers/api/videos/comment.ts24
1 files changed, 14 insertions, 10 deletions
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index e35247829..dc25e1e85 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -23,7 +23,9 @@ import {
23} from '../../../middlewares/validators/video-comments' 23} from '../../../middlewares/validators/video-comments'
24import { VideoModel } from '../../../models/video/video' 24import { VideoModel } from '../../../models/video/video'
25import { VideoCommentModel } from '../../../models/video/video-comment' 25import { VideoCommentModel } from '../../../models/video/video-comment'
26import { auditLoggerFactory, CommentAuditView } from '../../../helpers/audit-logger' 26import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
27import { AccountModel } from '../../../models/account/account'
28import { UserModel } from '../../../models/account/user'
27 29
28const auditLogger = auditLoggerFactory('comments') 30const auditLogger = auditLoggerFactory('comments')
29const videoCommentRouter = express.Router() 31const videoCommentRouter = express.Router()
@@ -86,7 +88,7 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo
86 let resultList: ResultList<VideoCommentModel> 88 let resultList: ResultList<VideoCommentModel>
87 89
88 if (video.commentsEnabled === true) { 90 if (video.commentsEnabled === true) {
89 resultList = await VideoCommentModel.listThreadCommentsForApi(res.locals.video.id, res.locals.videoCommentThread.id) 91 resultList = await VideoCommentModel.listThreadCommentsForApi(video.id, res.locals.videoCommentThread.id)
90 } else { 92 } else {
91 resultList = { 93 resultList = {
92 total: 0, 94 total: 0,
@@ -101,15 +103,17 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons
101 const videoCommentInfo: VideoCommentCreate = req.body 103 const videoCommentInfo: VideoCommentCreate = req.body
102 104
103 const comment = await sequelizeTypescript.transaction(async t => { 105 const comment = await sequelizeTypescript.transaction(async t => {
106 const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
107
104 return createVideoComment({ 108 return createVideoComment({
105 text: videoCommentInfo.text, 109 text: videoCommentInfo.text,
106 inReplyToComment: null, 110 inReplyToComment: null,
107 video: res.locals.video, 111 video: res.locals.video,
108 account: res.locals.oauth.token.User.Account 112 account
109 }, t) 113 }, t)
110 }) 114 })
111 115
112 auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new CommentAuditView(comment.toFormattedJSON())) 116 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
113 117
114 return res.json({ 118 return res.json({
115 comment: comment.toFormattedJSON() 119 comment: comment.toFormattedJSON()
@@ -120,19 +124,19 @@ async function addVideoCommentReply (req: express.Request, res: express.Response
120 const videoCommentInfo: VideoCommentCreate = req.body 124 const videoCommentInfo: VideoCommentCreate = req.body
121 125
122 const comment = await sequelizeTypescript.transaction(async t => { 126 const comment = await sequelizeTypescript.transaction(async t => {
127 const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
128
123 return createVideoComment({ 129 return createVideoComment({
124 text: videoCommentInfo.text, 130 text: videoCommentInfo.text,
125 inReplyToComment: res.locals.videoComment, 131 inReplyToComment: res.locals.videoComment,
126 video: res.locals.video, 132 video: res.locals.video,
127 account: res.locals.oauth.token.User.Account 133 account
128 }, t) 134 }, t)
129 }) 135 })
130 136
131 auditLogger.create(res.locals.oauth.token.User.Account.Actor.getIdentifier(), new CommentAuditView(comment.toFormattedJSON())) 137 auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
132 138
133 return res.json({ 139 return res.json({ comment: comment.toFormattedJSON() }).end()
134 comment: comment.toFormattedJSON()
135 }).end()
136} 140}
137 141
138async function removeVideoComment (req: express.Request, res: express.Response) { 142async function removeVideoComment (req: express.Request, res: express.Response) {
@@ -143,7 +147,7 @@ async function removeVideoComment (req: express.Request, res: express.Response)
143 }) 147 })
144 148
145 auditLogger.delete( 149 auditLogger.delete(
146 res.locals.oauth.token.User.Account.Actor.getIdentifier(), 150 getAuditIdFromRes(res),
147 new CommentAuditView(videoCommentInstance.toFormattedJSON()) 151 new CommentAuditView(videoCommentInstance.toFormattedJSON())
148 ) 152 )
149 logger.info('Video comment %d deleted.', videoCommentInstance.id) 153 logger.info('Video comment %d deleted.', videoCommentInstance.id)