]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-create.ts
Refractor activity pub lib/helpers
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-create.ts
1 import { Transaction } from 'sequelize'
2 import { ActivityCreate } from '../../../../shared/models/activitypub/activity'
3 import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../../models'
4 import { VideoAbuseInstance } from '../../../models/video/video-abuse-interface'
5 import { broadcastToFollowers, getAudience, unicastTo } from './misc'
6 import { getVideoAbuseActivityPubUrl } from '../../../helpers/activitypub'
7
8 async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
9 const byAccount = videoChannel.Account
10
11 const videoChannelObject = videoChannel.toActivityPubObject()
12 const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject)
13
14 return broadcastToFollowers(data, byAccount, [ byAccount ], t)
15 }
16
17 async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) {
18 const url = getVideoAbuseActivityPubUrl(videoAbuse)
19 const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject())
20
21 return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
22 }
23
24 async function createActivityData (url: string, byAccount: AccountInstance, object: any) {
25 const { to, cc } = await getAudience(byAccount)
26 const activity: ActivityCreate = {
27 type: 'Create',
28 id: url,
29 actor: byAccount.url,
30 to,
31 cc,
32 object
33 }
34
35 return activity
36 }
37
38 // ---------------------------------------------------------------------------
39
40 export {
41 sendCreateVideoChannel,
42 sendVideoAbuse,
43 createActivityData
44 }