]>
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) |
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 | 78 | async 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 | ||
96 | export { | |
54141398 | 97 | sendDeleteVideo, |
4cb6d457 | 98 | sendDeleteActor, |
418d092a C |
99 | sendDeleteVideoComment, |
100 | sendDeleteVideoPlaylist | |
54141398 C |
101 | } |
102 | ||
103 | // --------------------------------------------------------------------------- | |
104 | ||
453e83ea | 105 | function 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 | } |