]>
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' |
3fd3ab2d | 4 | import { VideoModel } from '../../../models/video/video' |
4cb6d457 | 5 | import { VideoCommentModel } from '../../../models/video/video-comment' |
3fd3ab2d | 6 | import { VideoShareModel } from '../../../models/video/video-share' |
c3badc81 | 7 | import { getDeleteActivityPubUrl } from '../url' |
e251f170 C |
8 | import { broadcastToActors, broadcastToFollowers, unicastTo } from './utils' |
9 | import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience' | |
8e0fd45e | 10 | import { logger } from '../../../helpers/logger' |
54141398 | 11 | |
3fd3ab2d | 12 | async function sendDeleteVideo (video: VideoModel, t: Transaction) { |
8e0fd45e C |
13 | logger.info('Creating job to broadcast delete of video %s.', video.url) |
14 | ||
c3badc81 | 15 | const url = getDeleteActivityPubUrl(video.url) |
50d6de9c | 16 | const byActor = video.VideoChannel.Account.Actor |
54141398 | 17 | |
c48e82b5 | 18 | const activity = buildDeleteActivity(url, video.url, byActor) |
54141398 | 19 | |
c48e82b5 | 20 | const actorsInvolved = await getActorsInvolvedInVideo(video, t) |
54141398 | 21 | |
c48e82b5 | 22 | return broadcastToFollowers(activity, byActor, actorsInvolved, t) |
54141398 C |
23 | } |
24 | ||
50d6de9c | 25 | async function sendDeleteActor (byActor: ActorModel, t: Transaction) { |
8e0fd45e C |
26 | logger.info('Creating job to broadcast delete of actor %s.', byActor.url) |
27 | ||
c3badc81 | 28 | const url = getDeleteActivityPubUrl(byActor.url) |
c48e82b5 | 29 | const activity = buildDeleteActivity(url, byActor.url, byActor) |
54141398 | 30 | |
f05a1c30 C |
31 | const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t) |
32 | actorsInvolved.push(byActor) | |
33 | ||
c48e82b5 | 34 | return broadcastToFollowers(activity, byActor, actorsInvolved, t) |
54141398 C |
35 | } |
36 | ||
4cb6d457 | 37 | async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) { |
8e0fd45e C |
38 | logger.info('Creating job to send delete of comment %s.', videoComment.url) |
39 | ||
73c08093 | 40 | const isVideoOrigin = videoComment.Video.isOwned() |
4cb6d457 | 41 | |
73c08093 | 42 | const url = getDeleteActivityPubUrl(videoComment.url) |
c3badc81 | 43 | const byActor = videoComment.Account.Actor |
73c08093 | 44 | const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t) |
4cb6d457 | 45 | |
73c08093 | 46 | const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t) |
c48e82b5 | 47 | actorsInvolvedInComment.push(byActor) // Add the actor that commented the video |
4cb6d457 | 48 | |
73c08093 | 49 | const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin) |
c48e82b5 | 50 | const activity = buildDeleteActivity(url, videoComment.url, byActor, audience) |
73c08093 C |
51 | |
52 | // This was a reply, send it to the parent actors | |
53 | const actorsException = [ byActor ] | |
c48e82b5 | 54 | await broadcastToActors(activity, byActor, threadParentComments.map(c => c.Account.Actor), actorsException) |
73c08093 C |
55 | |
56 | // Broadcast to our followers | |
c48e82b5 | 57 | await broadcastToFollowers(activity, byActor, [ byActor ], t) |
73c08093 C |
58 | |
59 | // Send to actors involved in the comment | |
c48e82b5 | 60 | if (isVideoOrigin) return broadcastToFollowers(activity, byActor, actorsInvolvedInComment, t, actorsException) |
73c08093 C |
61 | |
62 | // Send to origin | |
c48e82b5 | 63 | return unicastTo(activity, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl) |
4cb6d457 C |
64 | } |
65 | ||
54141398 C |
66 | // --------------------------------------------------------------------------- |
67 | ||
68 | export { | |
54141398 | 69 | sendDeleteVideo, |
4cb6d457 C |
70 | sendDeleteActor, |
71 | sendDeleteVideoComment | |
54141398 C |
72 | } |
73 | ||
74 | // --------------------------------------------------------------------------- | |
75 | ||
c48e82b5 | 76 | function buildDeleteActivity (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete { |
73c08093 C |
77 | const activity = { |
78 | type: 'Delete' as 'Delete', | |
54141398 | 79 | id: url, |
c3badc81 C |
80 | actor: byActor.url, |
81 | object | |
54141398 | 82 | } |
73c08093 C |
83 | |
84 | if (audience) return audiencify(activity, audience) | |
85 | ||
86 | return activity | |
54141398 | 87 | } |