]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-delete.ts
Improve AP validation for Notes
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-delete.ts
CommitLineData
54141398 1import { Transaction } from 'sequelize'
73c08093 2import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub'
50d6de9c 3import { ActorModel } from '../../../models/activitypub/actor'
3fd3ab2d 4import { VideoModel } from '../../../models/video/video'
4cb6d457 5import { VideoCommentModel } from '../../../models/video/video-comment'
3fd3ab2d 6import { VideoShareModel } from '../../../models/video/video-share'
c3badc81 7import { getDeleteActivityPubUrl } from '../url'
73c08093 8import { audiencify, broadcastToActors, broadcastToFollowers, getActorsInvolvedInVideo, getVideoCommentAudience, unicastTo } from './misc'
54141398 9
3fd3ab2d 10async function sendDeleteVideo (video: VideoModel, t: Transaction) {
c3badc81 11 const url = getDeleteActivityPubUrl(video.url)
50d6de9c 12 const byActor = video.VideoChannel.Account.Actor
54141398 13
c3badc81 14 const data = deleteActivityData(url, video.url, byActor)
54141398 15
50d6de9c
C
16 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
17 actorsInvolved.push(byActor)
54141398 18
50d6de9c 19 return broadcastToFollowers(data, byActor, actorsInvolved, t)
54141398
C
20}
21
50d6de9c 22async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
c3badc81
C
23 const url = getDeleteActivityPubUrl(byActor.url)
24 const data = deleteActivityData(url, byActor.url, byActor)
54141398 25
f05a1c30
C
26 const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
27 actorsInvolved.push(byActor)
28
29 return broadcastToFollowers(data, byActor, actorsInvolved, t)
54141398
C
30}
31
4cb6d457 32async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
73c08093 33 const isVideoOrigin = videoComment.Video.isOwned()
4cb6d457 34
73c08093 35 const url = getDeleteActivityPubUrl(videoComment.url)
c3badc81 36 const byActor = videoComment.Account.Actor
73c08093 37 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t)
4cb6d457 38
73c08093
C
39 const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t)
40 actorsInvolvedInComment.push(byActor)
4cb6d457 41
73c08093
C
42 const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin)
43 const data = deleteActivityData(url, videoComment.url, byActor, audience)
44
45 // This was a reply, send it to the parent actors
46 const actorsException = [ byActor ]
47 await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
48
49 // Broadcast to our followers
50 await broadcastToFollowers(data, byActor, [ byActor ], t)
51
52 // Send to actors involved in the comment
53 if (isVideoOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
54
55 // Send to origin
56 return unicastTo(data, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
4cb6d457
C
57}
58
54141398
C
59// ---------------------------------------------------------------------------
60
61export {
54141398 62 sendDeleteVideo,
4cb6d457
C
63 sendDeleteActor,
64 sendDeleteVideoComment
54141398
C
65}
66
67// ---------------------------------------------------------------------------
68
73c08093
C
69function deleteActivityData (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete {
70 const activity = {
71 type: 'Delete' as 'Delete',
54141398 72 id: url,
c3badc81
C
73 actor: byActor.url,
74 object
54141398 75 }
73c08093
C
76
77 if (audience) return audiencify(activity, audience)
78
79 return activity
54141398 80}