aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-delete.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-04 11:19:16 +0100
committerChocobozzz <me@florianbigard.com>2018-01-04 11:19:16 +0100
commit4cb6d4578893db310297d7e118ce2fb7ecb952a3 (patch)
treea89a2e2062ba7bb91e922f07a7950ee51e090ccf /server/lib/activitypub/process/process-delete.ts
parentcf117aaafc1e9ae1ab4c388fc5d2e5ba9349efee (diff)
downloadPeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.tar.gz
PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.tar.zst
PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.zip
Add ability to delete comments
Diffstat (limited to 'server/lib/activitypub/process/process-delete.ts')
-rw-r--r--server/lib/activitypub/process/process-delete.ts33
1 files changed, 30 insertions, 3 deletions
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts
index 523a31822..604570e74 100644
--- a/server/lib/activitypub/process/process-delete.ts
+++ b/server/lib/activitypub/process/process-delete.ts
@@ -6,6 +6,7 @@ import { AccountModel } from '../../../models/account/account'
6import { ActorModel } from '../../../models/activitypub/actor' 6import { ActorModel } from '../../../models/activitypub/actor'
7import { VideoModel } from '../../../models/video/video' 7import { VideoModel } from '../../../models/video/video'
8import { VideoChannelModel } from '../../../models/video/video-channel' 8import { VideoChannelModel } from '../../../models/video/video-channel'
9import { VideoCommentModel } from '../../../models/video/video-comment'
9import { getOrCreateActorAndServerAndModel } from '../actor' 10import { getOrCreateActorAndServerAndModel } from '../actor'
10 11
11async function processDeleteActivity (activity: ActivityDelete) { 12async function processDeleteActivity (activity: ActivityDelete) {
@@ -24,9 +25,16 @@ async function processDeleteActivity (activity: ActivityDelete) {
24 } 25 }
25 26
26 { 27 {
27 let videoObject = await VideoModel.loadByUrlAndPopulateAccount(activity.id) 28 const videoCommentInstance = await VideoCommentModel.loadByUrlAndPopulateAccount(activity.id)
28 if (videoObject !== undefined) { 29 if (videoCommentInstance) {
29 return processDeleteVideo(actor, videoObject) 30 return processDeleteVideoComment(actor, videoCommentInstance)
31 }
32 }
33
34 {
35 const videoInstance = await VideoModel.loadByUrlAndPopulateAccount(activity.id)
36 if (videoInstance) {
37 return processDeleteVideo(actor, videoInstance)
30 } 38 }
31 } 39 }
32 40
@@ -101,3 +109,22 @@ async function deleteRemoteVideoChannel (videoChannelToRemove: VideoChannelModel
101 109
102 logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid) 110 logger.info('Remote video channel with uuid %s removed.', videoChannelToRemove.Actor.uuid)
103} 111}
112
113async function processDeleteVideoComment (actor: ActorModel, videoComment: VideoCommentModel) {
114 const options = {
115 arguments: [ actor, videoComment ],
116 errorMessage: 'Cannot remove the remote video comment with many retries.'
117 }
118
119 await retryTransactionWrapper(deleteRemoteVideoComment, options)
120}
121
122function deleteRemoteVideoComment (actor: ActorModel, videoComment: VideoCommentModel) {
123 logger.debug('Removing remote video comment "%s".', videoComment.url)
124
125 return sequelizeTypescript.transaction(async t => {
126 await videoComment.destroy({ transaction: t })
127
128 logger.info('Remote video comment %s removed.', videoComment.url)
129 })
130}