]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-delete.ts
Add compatibility with other Linked Signature algorithms
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-delete.ts
1 import { Transaction } from 'sequelize'
2 import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub'
3 import { ActorModel } from '../../../models/activitypub/actor'
4 import { VideoModel } from '../../../models/video/video'
5 import { VideoCommentModel } from '../../../models/video/video-comment'
6 import { VideoShareModel } from '../../../models/video/video-share'
7 import { getDeleteActivityPubUrl } from '../url'
8 import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
9 import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience'
10 import { logger } from '../../../helpers/logger'
11
12 async function sendDeleteVideo (video: VideoModel, transaction: Transaction) {
13 logger.info('Creating job to broadcast delete of video %s.', video.url)
14
15 const byActor = video.VideoChannel.Account.Actor
16
17 const activityBuilder = (audience: ActivityAudience) => {
18 const url = getDeleteActivityPubUrl(video.url)
19
20 return buildDeleteActivity(url, video.url, byActor, audience)
21 }
22
23 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction })
24 }
25
26 async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
27 logger.info('Creating job to broadcast delete of actor %s.', byActor.url)
28
29 const url = getDeleteActivityPubUrl(byActor.url)
30 const activity = buildDeleteActivity(url, byActor.url, byActor)
31
32 const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
33 actorsInvolved.push(byActor)
34
35 return broadcastToFollowers(activity, byActor, actorsInvolved, t)
36 }
37
38 async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
39 logger.info('Creating job to send delete of comment %s.', videoComment.url)
40
41 const isVideoOrigin = videoComment.Video.isOwned()
42
43 const url = getDeleteActivityPubUrl(videoComment.url)
44 const byActor = videoComment.Account.Actor
45 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t)
46
47 const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t)
48 actorsInvolvedInComment.push(byActor) // Add the actor that commented the video
49
50 const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin)
51 const activity = buildDeleteActivity(url, videoComment.url, byActor, audience)
52
53 // This was a reply, send it to the parent actors
54 const actorsException = [ byActor ]
55 await broadcastToActors(activity, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
56
57 // Broadcast to our followers
58 await broadcastToFollowers(activity, byActor, [ byActor ], t)
59
60 // Send to actors involved in the comment
61 if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException)
62
63 // Send to origin
64 return unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
65 }
66
67 // ---------------------------------------------------------------------------
68
69 export {
70 sendDeleteVideo,
71 sendDeleteActor,
72 sendDeleteVideoComment
73 }
74
75 // ---------------------------------------------------------------------------
76
77 function buildDeleteActivity (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete {
78 const activity = {
79 type: 'Delete' as 'Delete',
80 id: url,
81 actor: byActor.url,
82 object
83 }
84
85 if (audience) return audiencify(activity, audience)
86
87 return activity
88 }