]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/send/send-delete.ts
Avoid too many requests and fetching outbox
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-delete.ts
... / ...
CommitLineData
1import { Transaction } from 'sequelize'
2import { ActivityDelete } from '../../../../shared/models/activitypub'
3import { ActorModel } from '../../../models/activitypub/actor'
4import { VideoModel } from '../../../models/video/video'
5import { VideoCommentModel } from '../../../models/video/video-comment'
6import { VideoShareModel } from '../../../models/video/video-share'
7import { getDeleteActivityPubUrl } from '../url'
8import { broadcastToFollowers } from './misc'
9
10async function sendDeleteVideo (video: VideoModel, t: Transaction) {
11 const url = getDeleteActivityPubUrl(video.url)
12 const byActor = video.VideoChannel.Account.Actor
13
14 const data = deleteActivityData(url, video.url, byActor)
15
16 const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
17 actorsInvolved.push(byActor)
18
19 return broadcastToFollowers(data, byActor, actorsInvolved, t)
20}
21
22async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
23 const url = getDeleteActivityPubUrl(byActor.url)
24 const data = deleteActivityData(url, byActor.url, byActor)
25
26 const actorsInvolved = await VideoShareModel.loadActorsByVideoOwner(byActor.id, t)
27 actorsInvolved.push(byActor)
28
29 return broadcastToFollowers(data, byActor, actorsInvolved, t)
30}
31
32async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
33 const url = getDeleteActivityPubUrl(videoComment.url)
34
35 const byActor = videoComment.Account.Actor
36 const data = deleteActivityData(url, videoComment.url, byActor)
37
38 const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t)
39 actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor)
40 actorsInvolved.push(byActor)
41
42 return broadcastToFollowers(data, byActor, actorsInvolved, t)
43}
44
45// ---------------------------------------------------------------------------
46
47export {
48 sendDeleteVideo,
49 sendDeleteActor,
50 sendDeleteVideoComment
51}
52
53// ---------------------------------------------------------------------------
54
55function deleteActivityData (url: string, object: string, byActor: ActorModel): ActivityDelete {
56 return {
57 type: 'Delete',
58 id: url,
59 actor: byActor.url,
60 object
61 }
62}