]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-delete.ts
Remove uneccessary details to link titles
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-delete.ts
CommitLineData
54141398 1import { Transaction } from 'sequelize'
444c0a0e 2import { getServerActor } from '@server/models/application/application'
73c08093 3import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub'
444c0a0e 4import { logger } from '../../../helpers/logger'
50d6de9c 5import { ActorModel } from '../../../models/activitypub/actor'
4cb6d457 6import { VideoCommentModel } from '../../../models/video/video-comment'
3fd3ab2d 7import { VideoShareModel } from '../../../models/video/video-share'
444c0a0e
C
8import { MActorUrl } from '../../../typings/models'
9import { MCommentOwnerVideo, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../typings/models/video'
10import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience'
c3badc81 11import { getDeleteActivityPubUrl } from '../url'
a2377d15 12import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
54141398 13
453e83ea 14async function sendDeleteVideo (video: MVideoAccountLight, transaction: Transaction) {
8e0fd45e
C
15 logger.info('Creating job to broadcast delete of video %s.', video.url)
16
50d6de9c 17 const byActor = video.VideoChannel.Account.Actor
54141398 18
a2377d15
C
19 const activityBuilder = (audience: ActivityAudience) => {
20 const url = getDeleteActivityPubUrl(video.url)
54141398 21
a2377d15
C
22 return buildDeleteActivity(url, video.url, byActor, audience)
23 }
54141398 24
a2377d15 25 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction })
54141398
C
26}
27
50d6de9c 28async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
8e0fd45e
C
29 logger.info('Creating job to broadcast delete of actor %s.', byActor.url)
30
c3badc81 31 const url = getDeleteActivityPubUrl(byActor.url)
c48e82b5 32 const activity = buildDeleteActivity(url, byActor.url, byActor)
54141398 33
df0b219d
C
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
f05a1c30
C
40 actorsInvolved.push(byActor)
41
c48e82b5 42 return broadcastToFollowers(activity, byActor, actorsInvolved, t)
54141398
C
43}
44
444c0a0e 45async function sendDeleteVideoComment (videoComment: MCommentOwnerVideo, t: Transaction) {
8e0fd45e
C
46 logger.info('Creating job to send delete of comment %s.', videoComment.url)
47
73c08093 48 const isVideoOrigin = videoComment.Video.isOwned()
4cb6d457 49
73c08093 50 const url = getDeleteActivityPubUrl(videoComment.url)
511765c9
C
51 const byActor = videoComment.isOwned()
52 ? videoComment.Account.Actor
53 : videoComment.Video.VideoChannel.Account.Actor
54
73c08093 55 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t)
c883db6d 56 const threadParentCommentsFiltered = threadParentComments.filter(c => !c.isDeleted())
4cb6d457 57
73c08093 58 const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t)
c48e82b5 59 actorsInvolvedInComment.push(byActor) // Add the actor that commented the video
4cb6d457 60
c883db6d 61 const audience = getVideoCommentAudience(videoComment, threadParentCommentsFiltered, actorsInvolvedInComment, isVideoOrigin)
c48e82b5 62 const activity = buildDeleteActivity(url, videoComment.url, byActor, audience)
73c08093
C
63
64 // This was a reply, send it to the parent actors
65 const actorsException = [ byActor ]
c883db6d 66 await broadcastToActors(activity, byActor, threadParentCommentsFiltered.map(c => c.Account.Actor), t, actorsException)
73c08093
C
67
68 // Broadcast to our followers
c48e82b5 69 await broadcastToFollowers(activity, byActor, [ byActor ], t)
73c08093
C
70
71 // Send to actors involved in the comment
c48e82b5 72 if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException)
73c08093
C
73
74 // Send to origin
47581df0 75 t.afterCommit(() => unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.getSharedInbox()))
4cb6d457
C
76}
77
453e83ea 78async function sendDeleteVideoPlaylist (videoPlaylist: MVideoPlaylistFullSummary, t: Transaction) {
418d092a
C
79 logger.info('Creating job to send delete of playlist %s.', videoPlaylist.url)
80
81 const byActor = videoPlaylist.OwnerAccount.Actor
82
83 const url = getDeleteActivityPubUrl(videoPlaylist.url)
84 const activity = buildDeleteActivity(url, videoPlaylist.url, byActor)
85
86 const serverActor = await getServerActor()
87 const toFollowersOf = [ byActor, serverActor ]
88
89 if (videoPlaylist.VideoChannel) toFollowersOf.push(videoPlaylist.VideoChannel.Actor)
90
91 return broadcastToFollowers(activity, byActor, toFollowersOf, t)
92}
93
54141398
C
94// ---------------------------------------------------------------------------
95
96export {
54141398 97 sendDeleteVideo,
4cb6d457 98 sendDeleteActor,
418d092a
C
99 sendDeleteVideoComment,
100 sendDeleteVideoPlaylist
54141398
C
101}
102
103// ---------------------------------------------------------------------------
104
453e83ea 105function buildDeleteActivity (url: string, object: string, byActor: MActorUrl, audience?: ActivityAudience): ActivityDelete {
73c08093
C
106 const activity = {
107 type: 'Delete' as 'Delete',
54141398 108 id: url,
c3badc81
C
109 actor: byActor.url,
110 object
54141398 111 }
73c08093
C
112
113 if (audience) return audiencify(activity, audience)
114
115 return activity
54141398 116}