aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
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
parentcf117aaafc1e9ae1ab4c388fc5d2e5ba9349efee (diff)
downloadPeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.tar.gz
PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.tar.zst
PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.zip
Add ability to delete comments
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/process/process-delete.ts33
-rw-r--r--server/lib/activitypub/send/send-delete.ts16
2 files changed, 45 insertions, 4 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}
diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts
index 4bc5db77e..1ca031898 100644
--- a/server/lib/activitypub/send/send-delete.ts
+++ b/server/lib/activitypub/send/send-delete.ts
@@ -2,6 +2,7 @@ import { Transaction } from 'sequelize'
2import { ActivityDelete } from '../../../../shared/models/activitypub' 2import { ActivityDelete } from '../../../../shared/models/activitypub'
3import { ActorModel } from '../../../models/activitypub/actor' 3import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video' 4import { VideoModel } from '../../../models/video/video'
5import { VideoCommentModel } from '../../../models/video/video-comment'
5import { VideoShareModel } from '../../../models/video/video-share' 6import { VideoShareModel } from '../../../models/video/video-share'
6import { broadcastToFollowers } from './misc' 7import { broadcastToFollowers } from './misc'
7 8
@@ -22,11 +23,24 @@ async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
22 return broadcastToFollowers(data, byActor, [ byActor ], t) 23 return broadcastToFollowers(data, byActor, [ byActor ], t)
23} 24}
24 25
26async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
27 const byActor = videoComment.Account.Actor
28
29 const data = deleteActivityData(videoComment.url, byActor)
30
31 const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t)
32 actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor)
33 actorsInvolved.push(byActor)
34
35 return broadcastToFollowers(data, byActor, actorsInvolved, t)
36}
37
25// --------------------------------------------------------------------------- 38// ---------------------------------------------------------------------------
26 39
27export { 40export {
28 sendDeleteVideo, 41 sendDeleteVideo,
29 sendDeleteActor 42 sendDeleteActor,
43 sendDeleteVideoComment
30} 44}
31 45
32// --------------------------------------------------------------------------- 46// ---------------------------------------------------------------------------