]>
Commit | Line | Data |
---|---|---|
1 | import { Transaction } from 'sequelize' | |
2 | import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub' | |
3 | import { ActorModel } from '../../../models/activitypub/actor' | |
4 | import { VideoCommentModel } from '../../../models/video/video-comment' | |
5 | import { VideoShareModel } from '../../../models/video/video-share' | |
6 | import { getDeleteActivityPubUrl } from '../url' | |
7 | import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' | |
8 | import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience' | |
9 | import { logger } from '../../../helpers/logger' | |
10 | import { getServerActor } from '../../../helpers/utils' | |
11 | import { MCommentOwnerVideoReply, MVideoAccountLight, MVideoPlaylistFullSummary } from '../../../typings/models/video' | |
12 | import { MActorUrl } from '../../../typings/models' | |
13 | ||
14 | async function sendDeleteVideo (video: MVideoAccountLight, 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 | ||
28 | async 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 | ||
45 | async function sendDeleteVideoComment (videoComment: MCommentOwnerVideoReply, 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.isOwned() | |
52 | ? videoComment.Account.Actor | |
53 | : videoComment.Video.VideoChannel.Account.Actor | |
54 | ||
55 | const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t) | |
56 | ||
57 | const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t) | |
58 | actorsInvolvedInComment.push(byActor) // Add the actor that commented the video | |
59 | ||
60 | const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin) | |
61 | const activity = buildDeleteActivity(url, videoComment.url, byActor, audience) | |
62 | ||
63 | // This was a reply, send it to the parent actors | |
64 | const actorsException = [ byActor ] | |
65 | await broadcastToActors(activity, byActor, threadParentComments.map(c => c.Account.Actor), t, actorsException) | |
66 | ||
67 | // Broadcast to our followers | |
68 | await broadcastToFollowers(activity, byActor, [ byActor ], t) | |
69 | ||
70 | // Send to actors involved in the comment | |
71 | if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException) | |
72 | ||
73 | // Send to origin | |
74 | t.afterCommit(() => unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl)) | |
75 | } | |
76 | ||
77 | async function sendDeleteVideoPlaylist (videoPlaylist: MVideoPlaylistFullSummary, t: Transaction) { | |
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 | ||
93 | // --------------------------------------------------------------------------- | |
94 | ||
95 | export { | |
96 | sendDeleteVideo, | |
97 | sendDeleteActor, | |
98 | sendDeleteVideoComment, | |
99 | sendDeleteVideoPlaylist | |
100 | } | |
101 | ||
102 | // --------------------------------------------------------------------------- | |
103 | ||
104 | function buildDeleteActivity (url: string, object: string, byActor: MActorUrl, audience?: ActivityAudience): ActivityDelete { | |
105 | const activity = { | |
106 | type: 'Delete' as 'Delete', | |
107 | id: url, | |
108 | actor: byActor.url, | |
109 | object | |
110 | } | |
111 | ||
112 | if (audience) return audiencify(activity, audience) | |
113 | ||
114 | return activity | |
115 | } |