2017-11-20 09:43:39 +01:00
|
|
|
import { Transaction } from 'sequelize'
|
2017-12-12 17:53:50 +01: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 09:43:39 +01:00
|
|
|
import { broadcastToFollowers, getAudience } from './misc'
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
async function sendAddVideo (video: VideoModel, t: Transaction) {
|
2017-11-20 09:43:39 +01:00
|
|
|
const byAccount = video.VideoChannel.Account
|
|
|
|
|
|
|
|
const videoObject = video.toActivityPubObject()
|
2017-11-30 11:31:15 +01:00
|
|
|
const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject, t)
|
2017-11-20 09:43:39 +01:00
|
|
|
|
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
2017-11-30 11:31:15 +01:00
|
|
|
async function addActivityData (
|
|
|
|
url: string,
|
2017-12-12 17:53:50 +01:00
|
|
|
byAccount: AccountModel,
|
|
|
|
video: VideoModel,
|
2017-11-30 11:31:15 +01:00
|
|
|
target: string,
|
|
|
|
object: any,
|
|
|
|
t: Transaction
|
2017-12-12 17:53:50 +01:00
|
|
|
): Promise<ActivityAdd> {
|
2017-11-20 09:43:39 +01:00
|
|
|
const videoPublic = video.privacy === VideoPrivacy.PUBLIC
|
|
|
|
|
2017-11-30 11:31:15 +01:00
|
|
|
const { to, cc } = await getAudience(byAccount, t, videoPublic)
|
2017-12-12 17:53:50 +01:00
|
|
|
|
|
|
|
return {
|
2017-11-20 09:43:39 +01:00
|
|
|
type: 'Add',
|
|
|
|
id: url,
|
|
|
|
actor: byAccount.url,
|
|
|
|
to,
|
|
|
|
cc,
|
|
|
|
object,
|
|
|
|
target
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
addActivityData,
|
|
|
|
sendAddVideo
|
|
|
|
}
|