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