From 69222afac8f8c41d90295b33f0695bbff352851e Mon Sep 17 00:00:00 2001 From: Julien Maulny Date: Fri, 15 Nov 2019 19:05:08 +0100 Subject: Soft delete video comments instead of detroy --- server/controllers/activitypub/client.ts | 13 ++++++++----- server/controllers/api/videos/comment.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'server/controllers') 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 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) const isPublic = true // Comments are always public - const audience = getAudience(videoComment.Account.Actor, isPublic) + let videoCommentObject = videoComment.toActivityPubObject(threadParentComments) - const videoCommentObject = audiencify(videoComment.toActivityPubObject(threadParentComments), audience) + if (videoComment.Account) { + const audience = getAudience(videoComment.Account.Actor, isPublic) + videoCommentObject = audiencify(videoCommentObject, audience) - if (req.path.endsWith('/activity')) { - const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience) - return activityPubResponse(activityPubContextify(data), res) + if (req.path.endsWith('/activity')) { + const data = buildCreateActivity(videoComment.url, videoComment.Account.Actor, videoCommentObject, audience) + return activityPubResponse(activityPubContextify(data), res) + } } 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 @@ import * as express from 'express' +import { cloneDeep } from 'lodash' import { ResultList } from '../../../../shared/models' import { VideoCommentCreate } from '../../../../shared/models/videos/video-comment.model' import { logger } from '../../../helpers/logger' import { getFormattedObjects } from '../../../helpers/utils' import { sequelizeTypescript } from '../../../initializers' -import { buildFormattedCommentTree, createVideoComment } from '../../../lib/video-comment' +import { buildFormattedCommentTree, createVideoComment, markCommentAsDeleted } from '../../../lib/video-comment' import { asyncMiddleware, asyncRetryTransactionMiddleware, @@ -177,19 +178,22 @@ async function addVideoCommentReply (req: express.Request, res: express.Response async function removeVideoComment (req: express.Request, res: express.Response) { const videoCommentInstance = res.locals.videoCommentFull + const videoCommentInstanceBefore = cloneDeep(videoCommentInstance) await sequelizeTypescript.transaction(async t => { - await videoCommentInstance.destroy({ transaction: t }) - if (videoCommentInstance.isOwned() || videoCommentInstance.Video.isOwned()) { await sendDeleteVideoComment(videoCommentInstance, t) } + + markCommentAsDeleted(videoCommentInstance) + + await videoCommentInstance.save() }) auditLogger.delete(getAuditIdFromRes(res), new CommentAuditView(videoCommentInstance.toFormattedJSON())) logger.info('Video comment %d deleted.', videoCommentInstance.id) - Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstance }) + Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstanceBefore }) return res.type('json').status(204).end() } -- cgit v1.2.3