PeerTube/server/lib/activitypub/send/send-add.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-11-20 08:43:39 +00:00
import { Transaction } from 'sequelize'
2017-12-12 16:53:50 +00:00
import { ActivityAdd } from '../../../../shared/models/activitypub'
import { VideoPrivacy } from '../../../../shared/models/videos'
import { AccountModel } from '../../../models/account/account'
import { VideoModel } from '../../../models/video/video'
2017-11-20 08:43:39 +00:00
import { broadcastToFollowers, getAudience } from './misc'
2017-12-12 16:53:50 +00:00
async function sendAddVideo (video: VideoModel, t: Transaction) {
2017-11-20 08:43:39 +00:00
const byAccount = video.VideoChannel.Account
const videoObject = video.toActivityPubObject()
const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject, t)
2017-11-20 08:43:39 +00:00
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
}
async function addActivityData (
url: string,
2017-12-12 16:53:50 +00:00
byAccount: AccountModel,
video: VideoModel,
target: string,
object: any,
t: Transaction
2017-12-12 16:53:50 +00:00
): Promise<ActivityAdd> {
2017-11-20 08:43:39 +00:00
const videoPublic = video.privacy === VideoPrivacy.PUBLIC
const { to, cc } = await getAudience(byAccount, t, videoPublic)
2017-12-12 16:53:50 +00:00
return {
2017-11-20 08:43:39 +00:00
type: 'Add',
id: url,
actor: byAccount.url,
to,
cc,
object,
target
}
}
// ---------------------------------------------------------------------------
export {
addActivityData,
sendAddVideo
}