aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/video-comment.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/video-comment.ts')
-rw-r--r--server/lib/video-comment.ts29
1 files changed, 26 insertions, 3 deletions
diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts
index 516c912a9..97aa639fb 100644
--- a/server/lib/video-comment.ts
+++ b/server/lib/video-comment.ts
@@ -1,10 +1,32 @@
1import { cloneDeep } from 'lodash'
1import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
3import { logger } from '@server/helpers/logger'
4import { sequelizeTypescript } from '@server/initializers/database'
2import { ResultList } from '../../shared/models' 5import { ResultList } from '../../shared/models'
3import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model' 6import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model'
4import { VideoCommentModel } from '../models/video/video-comment' 7import { VideoCommentModel } from '../models/video/video-comment'
8import { MAccountDefault, MComment, MCommentOwnerVideoReply, MVideoFullLight, MCommentOwnerVideo } from '../typings/models'
9import { sendCreateVideoComment, sendDeleteVideoComment } from './activitypub/send'
5import { getVideoCommentActivityPubUrl } from './activitypub/url' 10import { getVideoCommentActivityPubUrl } from './activitypub/url'
6import { sendCreateVideoComment } from './activitypub/send' 11import { Hooks } from './plugins/hooks'
7import { MAccountDefault, MComment, MCommentOwnerVideoReply, MVideoFullLight } from '../typings/models' 12
13async function removeComment (videoCommentInstance: MCommentOwnerVideo) {
14 const videoCommentInstanceBefore = cloneDeep(videoCommentInstance)
15
16 await sequelizeTypescript.transaction(async t => {
17 if (videoCommentInstance.isOwned() || videoCommentInstance.Video.isOwned()) {
18 await sendDeleteVideoComment(videoCommentInstance, t)
19 }
20
21 markCommentAsDeleted(videoCommentInstance)
22
23 await videoCommentInstance.save()
24 })
25
26 logger.info('Video comment %d deleted.', videoCommentInstance.id)
27
28 Hooks.runAction('action:api.video-comment.deleted', { comment: videoCommentInstanceBefore })
29}
8 30
9async function createVideoComment (obj: { 31async function createVideoComment (obj: {
10 text: string 32 text: string
@@ -73,7 +95,7 @@ function buildFormattedCommentTree (resultList: ResultList<VideoCommentModel>):
73 return thread 95 return thread
74} 96}
75 97
76function markCommentAsDeleted (comment: MCommentOwnerVideoReply): void { 98function markCommentAsDeleted (comment: MComment): void {
77 comment.text = '' 99 comment.text = ''
78 comment.deletedAt = new Date() 100 comment.deletedAt = new Date()
79 comment.accountId = null 101 comment.accountId = null
@@ -82,6 +104,7 @@ function markCommentAsDeleted (comment: MCommentOwnerVideoReply): void {
82// --------------------------------------------------------------------------- 104// ---------------------------------------------------------------------------
83 105
84export { 106export {
107 removeComment,
85 createVideoComment, 108 createVideoComment,
86 buildFormattedCommentTree, 109 buildFormattedCommentTree,
87 markCommentAsDeleted 110 markCommentAsDeleted