1 import { Transaction } from 'sequelize'
2 import { ActivityAudience, ActivityDelete } from '../../../../shared/models/activitypub'
3 import { ActorModel } from '../../../models/activitypub/actor'
4 import { VideoModel } from '../../../models/video/video'
5 import { VideoCommentModel } from '../../../models/video/video-comment'
6 import { VideoShareModel } from '../../../models/video/video-share'
7 import { getDeleteActivityPubUrl } from '../url'
8 import { broadcastToActors, broadcastToFollowers, unicastTo } from './utils'
9 import { audiencify, getActorsInvolvedInVideo, getVideoCommentAudience } from '../audience'
11 async function sendDeleteVideo (video: VideoModel, t: Transaction) {
12 const url = getDeleteActivityPubUrl(video.url)
13 const byActor = video.VideoChannel.Account.Actor
15 const data = deleteActivityData(url, video.url, byActor)
17 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
18 actorsInvolved.push(byActor)
20 return broadcastToFollowers(data, byActor, actorsInvolved, t)
23 async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
24 const url = getDeleteActivityPubUrl(byActor.url)
25 const data = deleteActivityData(url, byActor.url, byActor)
27 const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
28 actorsInvolved.push(byActor)
30 return broadcastToFollowers(data, byActor, actorsInvolved, t)
33 async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
34 const isVideoOrigin = videoComment.Video.isOwned()
36 const url = getDeleteActivityPubUrl(videoComment.url)
37 const byActor = videoComment.Account.Actor
38 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t)
40 const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t)
41 actorsInvolvedInComment.push(byActor)
43 const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin)
44 const data = deleteActivityData(url, videoComment.url, byActor, audience)
46 // This was a reply, send it to the parent actors
47 const actorsException = [ byActor ]
48 await broadcastToActors(data, byActor, threadParentComments.map(c => c.Account.Actor), actorsException)
50 // Broadcast to our followers
51 await broadcastToFollowers(data, byActor, [ byActor ], t)
53 // Send to actors involved in the comment
54 if (isVideoOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException)
57 return unicastTo(data, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
60 // ---------------------------------------------------------------------------
65 sendDeleteVideoComment
68 // ---------------------------------------------------------------------------
70 function deleteActivityData (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete {
72 type: 'Delete' as 'Delete',
78 if (audience) return audiencify(activity, audience)