]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-delete.ts
Refractor activity pub lib/helpers
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-delete.ts
1 import { Transaction } from 'sequelize'
2 import { ActivityDelete } from '../../../../shared/models/activitypub/activity'
3 import { database as db } from '../../../initializers'
4 import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models'
5 import { broadcastToFollowers } from './misc'
6
7 async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
8 const byAccount = videoChannel.Account
9
10 const data = await deleteActivityData(videoChannel.url, byAccount)
11
12 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
13 accountsInvolved.push(byAccount)
14
15 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
16 }
17
18 async function sendDeleteVideo (video: VideoInstance, t: Transaction) {
19 const byAccount = video.VideoChannel.Account
20
21 const data = await deleteActivityData(video.url, byAccount)
22
23 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
24 accountsInvolved.push(byAccount)
25
26 return broadcastToFollowers(data, byAccount, accountsInvolved, t)
27 }
28
29 async function sendDeleteAccount (account: AccountInstance, t: Transaction) {
30 const data = await deleteActivityData(account.url, account)
31
32 return broadcastToFollowers(data, account, [ account ], t)
33 }
34
35 // ---------------------------------------------------------------------------
36
37 export {
38 sendDeleteVideoChannel,
39 sendDeleteVideo,
40 sendDeleteAccount
41 }
42
43 // ---------------------------------------------------------------------------
44
45 async function deleteActivityData (url: string, byAccount: AccountInstance) {
46 const activity: ActivityDelete = {
47 type: 'Delete',
48 id: url,
49 actor: byAccount.url
50 }
51
52 return activity
53 }