diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/send/send-delete.ts | 12 | ||||
-rw-r--r-- | server/lib/video-comment.ts | 29 |
2 files changed, 32 insertions, 9 deletions
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts index fd3f06dec..2afd2c05d 100644 --- a/server/lib/activitypub/send/send-delete.ts +++ b/server/lib/activitypub/send/send-delete.ts | |||
@@ -1,15 +1,15 @@ | |||
1 | import { Transaction } from 'sequelize' | 1 | import { Transaction } from 'sequelize' |
2 | import { getServerActor } from '@server/models/application/application' | ||
2 | import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub' | 3 | import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub' |
4 | import { logger } from '../../../helpers/logger' | ||
3 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { VideoCommentModel } from '../../../models/video/video-comment' | 6 | import { VideoCommentModel } from '../../../models/video/video-comment' |
5 | import { VideoShareModel } from '../../../models/video/video-share' | 7 | import { VideoShareModel } from '../../../models/video/video-share' |
8 | import { MActorUrl } from '../../../typings/models' | ||
9 | import { MCommentOwnerVideo, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../typings/models/video' | ||
10 | import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience' | ||
6 | import { getDeleteActivityPubUrl } from '../url' | 11 | import { getDeleteActivityPubUrl } from '../url' |
7 | import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' | 12 | import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' |
8 | import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience' | ||
9 | import { logger } from '../../../helpers/logger' | ||
10 | import { MCommentOwnerVideoReply, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../typings/models/video' | ||
11 | import { MActorUrl } from '../../../typings/models' | ||
12 | import { getServerActor } from '@server/models/application/application' | ||
13 | 13 | ||
14 | async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) { | 14 | async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) { |
15 | logger.info('Creating job to broadcast delete of video %s.', video.url) | 15 | logger.info('Creating job to broadcast delete of video %s.', video.url) |
@@ -42,7 +42,7 @@ async function sendDeleteActor (byActor: ActorModel, t: Transaction) { | |||
42 | return broadcastToFollowers(activity, byActor, actorsInvolved, t) | 42 | return broadcastToFollowers(activity, byActor, actorsInvolved, t) |
43 | } | 43 | } |
44 | 44 | ||
45 | async function sendDeleteVideoComment (videoComment: MCommentOwnerVideoReply, t: Transaction) { | 45 | async function sendDeleteVideoComment (videoComment: MCommentOwnerVideo, t: Transaction) { |
46 | logger.info('Creating job to send delete of comment %s.', videoComment.url) | 46 | logger.info('Creating job to send delete of comment %s.', videoComment.url) |
47 | 47 | ||
48 | const isVideoOrigin = videoComment.Video.isOwned() | 48 | const isVideoOrigin = videoComment.Video.isOwned() |
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 @@ | |||
1 | import { cloneDeep } from 'lodash' | ||
1 | import * as Sequelize from 'sequelize' | 2 | import * as Sequelize from 'sequelize' |
3 | import { logger } from '@server/helpers/logger' | ||
4 | import { sequelizeTypescript } from '@server/initializers/database' | ||
2 | import { ResultList } from '../../shared/models' | 5 | import { ResultList } from '../../shared/models' |
3 | import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model' | 6 | import { VideoCommentThreadTree } from '../../shared/models/videos/video-comment.model' |
4 | import { VideoCommentModel } from '../models/video/video-comment' | 7 | import { VideoCommentModel } from '../models/video/video-comment' |
8 | import { MAccountDefault, MComment, MCommentOwnerVideoReply, MVideoFullLight, MCommentOwnerVideo } from '../typings/models' | ||
9 | import { sendCreateVideoComment, sendDeleteVideoComment } from './activitypub/send' | ||
5 | import { getVideoCommentActivityPubUrl } from './activitypub/url' | 10 | import { getVideoCommentActivityPubUrl } from './activitypub/url' |
6 | import { sendCreateVideoComment } from './activitypub/send' | 11 | import { Hooks } from './plugins/hooks' |
7 | import { MAccountDefault, MComment, MCommentOwnerVideoReply, MVideoFullLight } from '../typings/models' | 12 | |
13 | async 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 | ||
9 | async function createVideoComment (obj: { | 31 | async 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 | ||
76 | function markCommentAsDeleted (comment: MCommentOwnerVideoReply): void { | 98 | function 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 | ||
84 | export { | 106 | export { |
107 | removeComment, | ||
85 | createVideoComment, | 108 | createVideoComment, |
86 | buildFormattedCommentTree, | 109 | buildFormattedCommentTree, |
87 | markCommentAsDeleted | 110 | markCommentAsDeleted |