Fix lint
[oweals/peertube.git] / server / lib / activitypub / send / send-add.ts
1 import { Transaction } from 'sequelize'
2 import { ActivityAdd } from '../../../../shared/models/activitypub/activity'
3 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
4 import { AccountInstance, VideoInstance } from '../../../models'
5 import { broadcastToFollowers, getAudience } from './misc'
6
7 async function sendAddVideo (video: VideoInstance, t: Transaction) {
8   const byAccount = video.VideoChannel.Account
9
10   const videoObject = video.toActivityPubObject()
11   const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject, t)
12
13   return broadcastToFollowers(data, byAccount, [ byAccount ], t)
14 }
15
16 async function addActivityData (
17   url: string,
18   byAccount: AccountInstance,
19   video: VideoInstance,
20   target: string,
21   object: any,
22   t: Transaction
23 ) {
24   const videoPublic = video.privacy === VideoPrivacy.PUBLIC
25
26   const { to, cc } = await getAudience(byAccount, t, videoPublic)
27   const activity: ActivityAdd = {
28     type: 'Add',
29     id: url,
30     actor: byAccount.url,
31     to,
32     cc,
33     object,
34     target
35   }
36
37   return activity
38 }
39
40 // ---------------------------------------------------------------------------
41
42 export {
43   addActivityData,
44   sendAddVideo
45 }