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