aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorJulien Maulny <julien.maulny@protonmail.com>2019-11-15 19:05:08 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-12-04 09:36:45 +0100
commit69222afac8f8c41d90295b33f0695bbff352851e (patch)
tree63fe1faea94dd3bfc54e633631eecb275c969e54 /server/controllers
parent69c7f7525ddf13b7ced787d8b72ac74b43665517 (diff)
downloadPeerTube-69222afac8f8c41d90295b33f0695bbff352851e.tar.gz
PeerTube-69222afac8f8c41d90295b33f0695bbff352851e.tar.zst
PeerTube-69222afac8f8c41d90295b33f0695bbff352851e.zip
Soft delete video comments instead of detroy
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/activitypub/client.ts13
-rw-r--r--server/controllers/api/videos/comment.ts12
2 files changed, 16 insertions, 9 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index 453ced8bf..5ed0435ff 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -308,13 +308,16 @@ async function videoCommentController (req: express.Request, res: express.Respon
308 308
309 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) 309 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined)
310 const isPublic = true // Comments are always public 310 const isPublic = true // Comments are always public
311 const audience = getAudience(videoComment.Account.Actor, isPublic) 311 let videoCommentObject = videoComment.toActivityPubObject(threadParentComments)
312 312
313 const videoCommentObject = audiencify(videoComment.toActivityPubObject(threadParentComments), audience) 313 if (videoComment.Account) {
314 const audience = getAudience(videoComment.Account.Actor, isPublic)
315 videoCommentObject = audiencify(videoCommentObject, audience)
314 316
315 if (req.path.endsWith('/activity')) { 317 if (req.path.endsWith('/activity')) {
316 const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience) 318 const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience)
317 return activityPubResponse(activityPubContextify(data), res) 319 return activityPubResponse(activityPubContextify(data), res)
320 }
318 } 321 }
319 322
320 return activityPubResponse(activityPubContextify(videoCommentObject), res) 323 return activityPubResponse(activityPubContextify(videoCommentObject), res)
diff --git a/server/controllers/api/videos/comment.ts b/server/controllers/api/videos/comment.ts
index b2b06b170..5f3fed5c0 100644
--- a/server/controllers/api/videos/comment.ts
+++ b/server/controllers/api/videos/comment.ts
@@ -1,10 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { cloneDeep } from 'lodash'
2import { ResultList } from '../../../../shared/models' 3import { ResultList } from '../../../../shared/models'
3import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' 4import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model'
4import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
5import { getFormattedObjects } from '../../../helpers/utils' 6import { getFormattedObjects } from '../../../helpers/utils'
6import { sequelizeTypescript } from '../../../initializers' 7import { sequelizeTypescript } from '../../../initializers'
7import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' 8import { buildFormattedCommentTree, createVideoComment, markCommentAsDeleted } from '../../../lib/video-comment'
8import { 9import {
9 asyncMiddleware, 10 asyncMiddleware,
10 asyncRetryTransactionMiddleware, 11 asyncRetryTransactionMiddleware,
@@ -177,19 +178,22 @@ async function addVideoCommentReply (req: express.Request, res: express.Response
177 178
178async function removeVideoComment (req: express.Request, res: express.Response) { 179async function removeVideoComment (req: express.Request, res: express.Response) {
179 const videoCommentInstance = res.locals.videoCommentFull 180 const videoCommentInstance = res.locals.videoCommentFull
181 const videoCommentInstanceBefore = cloneDeep(videoCommentInstance)
180 182
181 await sequelizeTypescript.transaction(async t => { 183 await sequelizeTypescript.transaction(async t => {
182 await videoCommentInstance.destroy({ transaction: t })
183
184 if (videoCommentInstance.isOwned() || videoCommentInstance.Video.isOwned()) { 184 if (videoCommentInstance.isOwned() || videoCommentInstance.Video.isOwned()) {
185 await sendDeleteVideoComment(videoCommentInstance, t) 185 await sendDeleteVideoComment(videoCommentInstance, t)
186 } 186 }
187
188 markCommentAsDeleted(videoCommentInstance)
189
190 await videoCommentInstance.save()
187 }) 191 })
188 192
189 auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) 193 auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON()))
190 logger.info('Video comment %d deleted.', videoCommentInstance.id) 194 logger.info('Video comment %d deleted.', videoCommentInstance.id)
191 195
192 Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstance }) 196 Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstanceBefore })
193 197
194 return res.type('json').status(204).end() 198 return res.type('json').status(204).end()
195} 199}