]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/send/send-delete.ts
Fix nginx template on dual stack server
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-delete.ts
... / ...
CommitLineData
1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub'
3import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video'
5import { VideoCommentModel } from '../../../models/video/video-comment'
6import { VideoShareModel } from '../../../models/video/video-share'
7import { getDeleteActivityPubUrl } from '../url'
8import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
9import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience'
10import { logger } from '../../../helpers/logger'
11import { VideoPlaylistModel } from '../../../models/video/video-playlist'
12import { getServerActor } from '../../../helpers/utils'
13
14async function sendDeleteVideo (video: VideoModel, transaction: Transaction) {
15 logger.info('Creating job to broadcast delete of video %s.', video.url)
16
17 const byActor = video.VideoChannel.Account.Actor
18
19 const activityBuilder = (audience: ActivityAudience) => {
20 const url = getDeleteActivityPubUrl(video.url)
21
22 return buildDeleteActivity(url, video.url, byActor, audience)
23 }
24
25 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction })
26}
27
28async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
29 logger.info('Creating job to broadcast delete of actor %s.', byActor.url)
30
31 const url = getDeleteActivityPubUrl(byActor.url)
32 const activity = buildDeleteActivity(url, byActor.url, byActor)
33
34 const actorsInvolved = await VideoShareModel.loadActorsWhoSharedVideosOf(byActor.id, t)
35
36 // In case the actor did not have any videos
37 const serverActor = await getServerActor()
38 actorsInvolved.push(serverActor)
39
40 actorsInvolved.push(byActor)
41
42 return broadcastToFollowers(activity, byActor, actorsInvolved, t)
43}
44
45async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
46 logger.info('Creating job to send delete of comment %s.', videoComment.url)
47
48 const isVideoOrigin = videoComment.Video.isOwned()
49
50 const url = getDeleteActivityPubUrl(videoComment.url)
51 const byActor = videoComment.Account.Actor
52 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t)
53
54 const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t)
55 actorsInvolvedInComment.push(byActor) // Add the actor that commented the video
56
57 const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin)
58 const activity = buildDeleteActivity(url, videoComment.url, byActor, audience)
59
60 // This was a reply, send it to the parent actors
61 const actorsException = [ byActor ]
62 await broadcastToActors(activity, byActor, threadParentComments.map(c => c.Account.Actor), t, actorsException)
63
64 // Broadcast to our followers
65 await broadcastToFollowers(activity, byActor, [ byActor ], t)
66
67 // Send to actors involved in the comment
68 if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException)
69
70 // Send to origin
71 t.afterCommit(() => unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl))
72}
73
74async function sendDeleteVideoPlaylist (videoPlaylist: VideoPlaylistModel, t: Transaction) {
75 logger.info('Creating job to send delete of playlist %s.', videoPlaylist.url)
76
77 const byActor = videoPlaylist.OwnerAccount.Actor
78
79 const url = getDeleteActivityPubUrl(videoPlaylist.url)
80 const activity = buildDeleteActivity(url, videoPlaylist.url, byActor)
81
82 const serverActor = await getServerActor()
83 const toFollowersOf = [ byActor, serverActor ]
84
85 if (videoPlaylist.VideoChannel) toFollowersOf.push(videoPlaylist.VideoChannel.Actor)
86
87 return broadcastToFollowers(activity, byActor, toFollowersOf, t)
88}
89
90// ---------------------------------------------------------------------------
91
92export {
93 sendDeleteVideo,
94 sendDeleteActor,
95 sendDeleteVideoComment,
96 sendDeleteVideoPlaylist
97}
98
99// ---------------------------------------------------------------------------
100
101function buildDeleteActivity (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete {
102 const activity = {
103 type: 'Delete' as 'Delete',
104 id: url,
105 actor: byActor.url,
106 object
107 }
108
109 if (audience) return audiencify(activity, audience)
110
111 return activity
112}