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.ts35
1 files changed, 10 insertions, 25 deletions
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index 5070bb3c0..45ff969d9 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -1,11 +1,12 @@
1import * as express from 'express' 1import * as express from 'express'
2import { cloneDeep } from 'lodash'
3import { ResultList } from '../../../../shared/models' 2import { ResultList } from '../../../../shared/models'
4import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' 3import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
5import { logger } from '../../../helpers/logger' 4import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
6import { getFormattedObjects } from '../../../helpers/utils' 5import { getFormattedObjects } from '../../../helpers/utils'
7import { sequelizeTypescript } from '../../../initializers/database' 6import { sequelizeTypescript } from '../../../initializers/database'
8import { buildFormattedCommentTree, createVideoComment, markCommentAsDeleted } from '../../../lib/video-comment' 7import { Notifier } from '../../../lib/notifier'
8import { Hooks } from '../../../lib/plugins/hooks'
9import { buildFormattedCommentTree, createVideoComment, removeComment } from '../../../lib/video-comment'
9import { 10import {
10 asyncMiddleware, 11 asyncMiddleware,
11 asyncRetryTransactionMiddleware, 12 asyncRetryTransactionMiddleware,
@@ -23,12 +24,8 @@ import {
23 removeVideoCommentValidator, 24 removeVideoCommentValidator,
24 videoCommentThreadsSortValidator 25 videoCommentThreadsSortValidator
25} from '../../../middlewares/validators' 26} from '../../../middlewares/validators'
26import { VideoCommentModel } from '../../../models/video/video-comment'
27import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
28import { AccountModel } from '../../../models/account/account' 27import { AccountModel } from '../../../models/account/account'
29import { Notifier } from '../../../lib/notifier' 28import { VideoCommentModel } from '../../../models/video/video-comment'
30import { Hooks } from '../../../lib/plugins/hooks'
31import { sendDeleteVideoComment } from '../../../lib/activitypub/send'
32 29
33const auditLogger = auditLoggerFactory('comments') 30const auditLogger = auditLoggerFactory('comments')
34const videoCommentRouter = express.Router() 31const videoCommentRouter = express.Router()
@@ -81,6 +78,7 @@ async function listVideoThreads (req: express.Request, res: express.Response) {
81 if (video.commentsEnabled === true) { 78 if (video.commentsEnabled === true) {
82 const apiOptions = await Hooks.wrapObject({ 79 const apiOptions = await Hooks.wrapObject({
83 videoId: video.id, 80 videoId: video.id,
81 isVideoOwned: video.isOwned(),
84 start: req.query.start, 82 start: req.query.start,
85 count: req.query.count, 83 count: req.query.count,
86 sort: req.query.sort, 84 sort: req.query.sort,
@@ -111,6 +109,7 @@ async function listVideoThreadComments (req: express.Request, res: express.Respo
111 if (video.commentsEnabled === true) { 109 if (video.commentsEnabled === true) {
112 const apiOptions = await Hooks.wrapObject({ 110 const apiOptions = await Hooks.wrapObject({
113 videoId: video.id, 111 videoId: video.id,
112 isVideoOwned: video.isOwned(),
114 threadId: res.locals.videoCommentThread.id, 113 threadId: res.locals.videoCommentThread.id,
115 user 114 user
116 }, 'filter:api.video-thread-comments.list.params') 115 }, 'filter:api.video-thread-comments.list.params')
@@ -149,9 +148,7 @@ async function addVideoCommentThread (req: express.Request, res: express.Respons
149 148
150 Hooks.runAction('action:api.video-thread.created', { comment }) 149 Hooks.runAction('action:api.video-thread.created', { comment })
151 150
152 return res.json({ 151 return res.json({ comment: comment.toFormattedJSON() })
153 comment: comment.toFormattedJSON()
154 }).end()
155} 152}
156 153
157async function addVideoCommentReply (req: express.Request, res: express.Response) { 154async function addVideoCommentReply (req: express.Request, res: express.Response) {
@@ -173,27 +170,15 @@ async function addVideoCommentReply (req: express.Request, res: express.Response
173 170
174 Hooks.runAction('action:api.video-comment-reply.created', { comment }) 171 Hooks.runAction('action:api.video-comment-reply.created', { comment })
175 172
176 return res.json({ comment: comment.toFormattedJSON() }).end() 173 return res.json({ comment: comment.toFormattedJSON() })
177} 174}
178 175
179async function removeVideoComment (req: express.Request, res: express.Response) { 176async function removeVideoComment (req: express.Request, res: express.Response) {
180 const videoCommentInstance = res.locals.videoCommentFull 177 const videoCommentInstance = res.locals.videoCommentFull
181 const videoCommentInstanceBefore = cloneDeep(videoCommentInstance)
182
183 await sequelizeTypescript.transaction(async t => {
184 if (videoCommentInstance.isOwned() || videoCommentInstance.Video.isOwned()) {
185 await sendDeleteVideoComment(videoCommentInstance, t)
186 }
187 178
188 markCommentAsDeleted(videoCommentInstance) 179 await removeComment(videoCommentInstance)
189
190 await videoCommentInstance.save()
191 })
192 180
193 auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) 181 auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON()))
194 logger.info('Video comment %d deleted.', videoCommentInstance.id)
195
196 Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstanceBefore })
197 182
198 return res.type('json').status(204).end() 183 return res.type('json').status(204).end()
199} 184}