]>
Commit | Line | Data |
---|---|---|
54141398 | 1 | import { Transaction } from 'sequelize' |
73c08093 | 2 | import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub' |
50d6de9c | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
4cb6d457 | 4 | import { VideoCommentModel } from '../../../models/video/video-comment' |
3fd3ab2d | 5 | import { VideoShareModel } from '../../../models/video/video-share' |
c3badc81 | 6 | import { getDeleteActivityPubUrl } from '../url' |
a2377d15 | 7 | import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' |
e251f170 | 8 | import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience' |
8e0fd45e | 9 | import { logger } from '../../../helpers/logger' |
418d092a | 10 | import { getServerActor } from '../../../helpers/utils' |
453e83ea C |
11 | import { MCommentOwnerVideoReply, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../typings/models/video' |
12 | import { MActorUrl } from '../../../typings/models' | |
54141398 | 13 | |
453e83ea | 14 | async 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 | 28 | async 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 | ||
453e83ea | 45 | async function sendDeleteVideoComment (videoComment: MCommentOwnerVideoReply, 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) |
4cb6d457 | 56 | |
73c08093 | 57 | const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t) |
c48e82b5 | 58 | actorsInvolvedInComment.push(byActor) // Add the actor that commented the video |
4cb6d457 | 59 | |
73c08093 | 60 | const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin) |
c48e82b5 | 61 | const activity = buildDeleteActivity(url, videoComment.url, byActor, audience) |
73c08093 C |
62 | |
63 | // This was a reply, send it to the parent actors | |
64 | const actorsException = [ byActor ] | |
2284f202 | 65 | await broadcastToActors(activity, byActor, threadParentComments.map(c => c.Account.Actor), t, actorsException) |
73c08093 C |
66 | |
67 | // Broadcast to our followers | |
c48e82b5 | 68 | await broadcastToFollowers(activity, byActor, [ byActor ], t) |
73c08093 C |
69 | |
70 | // Send to actors involved in the comment | |
c48e82b5 | 71 | if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException) |
73c08093 C |
72 | |
73 | // Send to origin | |
47581df0 | 74 | t.afterCommit(() => unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.getSharedInbox())) |
4cb6d457 C |
75 | } |
76 | ||
453e83ea | 77 | async function sendDeleteVideoPlaylist (videoPlaylist: MVideoPlaylistFullSummary, t: Transaction) { |
418d092a C |
78 | logger.info('Creating job to send delete of playlist %s.', videoPlaylist.url) |
79 | ||
80 | const byActor = videoPlaylist.OwnerAccount.Actor | |
81 | ||
82 | const url = getDeleteActivityPubUrl(videoPlaylist.url) | |
83 | const activity = buildDeleteActivity(url, videoPlaylist.url, byActor) | |
84 | ||
85 | const serverActor = await getServerActor() | |
86 | const toFollowersOf = [ byActor, serverActor ] | |
87 | ||
88 | if (videoPlaylist.VideoChannel) toFollowersOf.push(videoPlaylist.VideoChannel.Actor) | |
89 | ||
90 | return broadcastToFollowers(activity, byActor, toFollowersOf, t) | |
91 | } | |
92 | ||
54141398 C |
93 | // --------------------------------------------------------------------------- |
94 | ||
95 | export { | |
54141398 | 96 | sendDeleteVideo, |
4cb6d457 | 97 | sendDeleteActor, |
418d092a C |
98 | sendDeleteVideoComment, |
99 | sendDeleteVideoPlaylist | |
54141398 C |
100 | } |
101 | ||
102 | // --------------------------------------------------------------------------- | |
103 | ||
453e83ea | 104 | function buildDeleteActivity (url: string, object: string, byActor: MActorUrl, audience?: ActivityAudience): ActivityDelete { |
73c08093 C |
105 | const activity = { |
106 | type: 'Delete' as 'Delete', | |
54141398 | 107 | id: url, |
c3badc81 C |
108 | actor: byActor.url, |
109 | object | |
54141398 | 110 | } |
73c08093 C |
111 | |
112 | if (audience) return audiencify(activity, audience) | |
113 | ||
114 | return activity | |
54141398 | 115 | } |