]>
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' | |
54141398 | 10 | |
3fd3ab2d | 11 | async function sendDeleteVideo (video: VideoModel, t: Transaction) { |
c3badc81 | 12 | const url = getDeleteActivityPubUrl(video.url) |
50d6de9c | 13 | const byActor = video.VideoChannel.Account.Actor |
54141398 | 14 | |
c3badc81 | 15 | const data = deleteActivityData(url, video.url, byActor) |
54141398 | 16 | |
50d6de9c C |
17 | const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t) |
18 | actorsInvolved.push(byActor) | |
54141398 | 19 | |
50d6de9c | 20 | return broadcastToFollowers(data, byActor, actorsInvolved, t) |
54141398 C |
21 | } |
22 | ||
50d6de9c | 23 | async function sendDeleteActor (byActor: ActorModel, t: Transaction) { |
c3badc81 C |
24 | const url = getDeleteActivityPubUrl(byActor.url) |
25 | const data = deleteActivityData(url, byActor.url, byActor) | |
54141398 | 26 | |
f05a1c30 C |
27 | const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t) |
28 | actorsInvolved.push(byActor) | |
29 | ||
30 | return broadcastToFollowers(data, byActor, actorsInvolved, t) | |
54141398 C |
31 | } |
32 | ||
4cb6d457 | 33 | async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) { |
73c08093 | 34 | const isVideoOrigin = videoComment.Video.isOwned() |
4cb6d457 | 35 | |
73c08093 | 36 | const url = getDeleteActivityPubUrl(videoComment.url) |
c3badc81 | 37 | const byActor = videoComment.Account.Actor |
73c08093 | 38 | const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, t) |
4cb6d457 | 39 | |
73c08093 C |
40 | const actorsInvolvedInComment = await getActorsInvolvedInVideo(videoComment.Video, t) |
41 | actorsInvolvedInComment.push(byActor) | |
4cb6d457 | 42 | |
73c08093 C |
43 | const audience = getVideoCommentAudience(videoComment, threadParentComments, actorsInvolvedInComment, isVideoOrigin) |
44 | const data = deleteActivityData(url, videoComment.url, byActor, audience) | |
45 | ||
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) | |
49 | ||
50 | // Broadcast to our followers | |
51 | await broadcastToFollowers(data, byActor, [ byActor ], t) | |
52 | ||
53 | // Send to actors involved in the comment | |
54 | if (isVideoOrigin) return broadcastToFollowers(data, byActor, actorsInvolvedInComment, t, actorsException) | |
55 | ||
56 | // Send to origin | |
57 | return unicastTo(data, byActor, videoComment.Video.VideoChannel.Account.Actor.sharedInboxUrl) | |
4cb6d457 C |
58 | } |
59 | ||
54141398 C |
60 | // --------------------------------------------------------------------------- |
61 | ||
62 | export { | |
54141398 | 63 | sendDeleteVideo, |
4cb6d457 C |
64 | sendDeleteActor, |
65 | sendDeleteVideoComment | |
54141398 C |
66 | } |
67 | ||
68 | // --------------------------------------------------------------------------- | |
69 | ||
73c08093 C |
70 | function deleteActivityData (url: string, object: string, byActor: ActorModel, audience?: ActivityAudience): ActivityDelete { |
71 | const activity = { | |
72 | type: 'Delete' as 'Delete', | |
54141398 | 73 | id: url, |
c3badc81 C |
74 | actor: byActor.url, |
75 | object | |
54141398 | 76 | } |
73c08093 C |
77 | |
78 | if (audience) return audiencify(activity, audience) | |
79 | ||
80 | return activity | |
54141398 | 81 | } |