2017-11-20 02:43:39 -06:00
|
|
|
import { Transaction } from 'sequelize'
|
2017-11-21 11:23:10 -06:00
|
|
|
import { ActivityAdd } from '../../../../shared/index'
|
|
|
|
import { ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub/activity'
|
2017-11-20 02:43:39 -06:00
|
|
|
import { AccountInstance, VideoInstance } from '../../../models'
|
|
|
|
import { VideoChannelInstance } from '../../../models/video/video-channel-interface'
|
2017-11-21 11:23:10 -06:00
|
|
|
import { getAnnounceActivityPubUrl } from '../url'
|
2017-11-20 02:43:39 -06:00
|
|
|
import { broadcastToFollowers } from './misc'
|
|
|
|
import { addActivityData } from './send-add'
|
|
|
|
import { createActivityData } from './send-create'
|
|
|
|
|
|
|
|
async function sendVideoAnnounce (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
|
|
|
const url = getAnnounceActivityPubUrl(video.url, byAccount)
|
|
|
|
|
|
|
|
const videoChannel = video.VideoChannel
|
|
|
|
const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject())
|
|
|
|
|
|
|
|
const data = await announceActivityData(url, byAccount, announcedActivity)
|
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendVideoChannelAnnounce (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
|
|
|
|
const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
|
|
|
|
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject())
|
|
|
|
|
|
|
|
const data = await announceActivityData(url, byAccount, announcedActivity)
|
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
2017-11-21 11:23:10 -06:00
|
|
|
async function announceActivityData (url: string, byAccount: AccountInstance, object: ActivityCreate | ActivityAdd) {
|
|
|
|
const activity: ActivityAnnounce = {
|
2017-11-20 02:43:39 -06:00
|
|
|
type: 'Announce',
|
|
|
|
id: url,
|
|
|
|
actor: byAccount.url,
|
|
|
|
object
|
|
|
|
}
|
|
|
|
|
|
|
|
return activity
|
|
|
|
}
|
2017-11-21 11:23:10 -06:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendVideoAnnounce,
|
|
|
|
sendVideoChannelAnnounce,
|
|
|
|
announceActivityData
|
|
|
|
}
|