Add ability to delete comments
[oweals/peertube.git] / server / lib / activitypub / send / send-delete.ts
1 import { Transaction } from 'sequelize'
2 import { 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 { broadcastToFollowers } from './misc'
8
9 async function sendDeleteVideo (video: VideoModel, t: Transaction) {
10   const byActor = video.VideoChannel.Account.Actor
11
12   const data = deleteActivityData(video.url, byActor)
13
14   const actorsInvolved = await VideoShareModel.loadActorsByShare(video.id, t)
15   actorsInvolved.push(byActor)
16
17   return broadcastToFollowers(data, byActor, actorsInvolved, t)
18 }
19
20 async function sendDeleteActor (byActor: ActorModel, t: Transaction) {
21   const data = deleteActivityData(byActor.url, byActor)
22
23   return broadcastToFollowers(data, byActor, [ byActor ], t)
24 }
25
26 async function sendDeleteVideoComment (videoComment: VideoCommentModel, t: Transaction) {
27   const byActor = videoComment.Account.Actor
28
29   const data = deleteActivityData(videoComment.url, byActor)
30
31   const actorsInvolved = await VideoShareModel.loadActorsByShare(videoComment.Video.id, t)
32   actorsInvolved.push(videoComment.Video.VideoChannel.Account.Actor)
33   actorsInvolved.push(byActor)
34
35   return broadcastToFollowers(data, byActor, actorsInvolved, t)
36 }
37
38 // ---------------------------------------------------------------------------
39
40 export {
41   sendDeleteVideo,
42   sendDeleteActor,
43   sendDeleteVideoComment
44 }
45
46 // ---------------------------------------------------------------------------
47
48 function deleteActivityData (url: string, byActor: ActorModel): ActivityDelete {
49   return {
50     type: 'Delete',
51     id: url,
52     actor: byActor.url
53   }
54 }