2017-11-20 02:43:39 -06:00
|
|
|
import { Transaction } from 'sequelize'
|
|
|
|
import { ActivityAdd } from '../../../../shared/models/activitypub/activity'
|
|
|
|
import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
|
|
|
|
import { AccountInstance, VideoInstance } from '../../../models'
|
|
|
|
import { broadcastToFollowers, getAudience } from './misc'
|
|
|
|
|
|
|
|
async function sendAddVideo (video: VideoInstance, t: Transaction) {
|
|
|
|
const byAccount = video.VideoChannel.Account
|
|
|
|
|
|
|
|
const videoObject = video.toActivityPubObject()
|
2017-11-30 04:31:15 -06:00
|
|
|
const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject, t)
|
2017-11-20 02:43:39 -06:00
|
|
|
|
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
2017-11-30 04:31:15 -06:00
|
|
|
async function addActivityData (
|
|
|
|
url: string,
|
|
|
|
byAccount: AccountInstance,
|
|
|
|
video: VideoInstance,
|
|
|
|
target: string,
|
|
|
|
object: any,
|
|
|
|
t: Transaction
|
|
|
|
) {
|
2017-11-20 02:43:39 -06:00
|
|
|
const videoPublic = video.privacy === VideoPrivacy.PUBLIC
|
|
|
|
|
2017-11-30 04:31:15 -06:00
|
|
|
const { to, cc } = await getAudience(byAccount, t, videoPublic)
|
2017-11-20 02:43:39 -06:00
|
|
|
const activity: ActivityAdd = {
|
|
|
|
type: 'Add',
|
|
|
|
id: url,
|
|
|
|
actor: byAccount.url,
|
|
|
|
to,
|
|
|
|
cc,
|
|
|
|
object,
|
|
|
|
target
|
|
|
|
}
|
|
|
|
|
|
|
|
return activity
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
addActivityData,
|
|
|
|
sendAddVideo
|
|
|
|
}
|