2017-11-20 03:43:39 -05:00
|
|
|
import { Transaction } from 'sequelize'
|
2017-11-21 12:23:10 -05:00
|
|
|
import { ActivityAdd } from '../../../../shared/index'
|
2017-11-27 08:44:51 -05:00
|
|
|
import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub/activity'
|
2017-11-20 03:43:39 -05:00
|
|
|
import { AccountInstance, VideoInstance } from '../../../models'
|
|
|
|
import { VideoChannelInstance } from '../../../models/video/video-channel-interface'
|
2017-11-21 12:23:10 -05:00
|
|
|
import { getAnnounceActivityPubUrl } from '../url'
|
2017-11-27 08:44:51 -05:00
|
|
|
import {
|
|
|
|
broadcastToFollowers,
|
|
|
|
getAccountsInvolvedInVideo,
|
|
|
|
getAccountsInvolvedInVideoChannel,
|
|
|
|
getAudience,
|
|
|
|
getObjectFollowersAudience,
|
|
|
|
getOriginVideoAudience,
|
|
|
|
getOriginVideoChannelAudience,
|
|
|
|
unicastTo
|
|
|
|
} from './misc'
|
2017-11-20 03:43:39 -05:00
|
|
|
import { addActivityData } from './send-add'
|
|
|
|
import { createActivityData } from './send-create'
|
|
|
|
|
2017-11-27 08:44:51 -05:00
|
|
|
async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
2017-11-20 03:43:39 -05:00
|
|
|
const url = getAnnounceActivityPubUrl(video.url, byAccount)
|
|
|
|
|
|
|
|
const videoChannel = video.VideoChannel
|
|
|
|
const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject())
|
|
|
|
|
2017-11-27 08:44:51 -05:00
|
|
|
const accountsToForwardView = await getAccountsInvolvedInVideo(video)
|
|
|
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
|
|
|
const data = await announceActivityData(url, byAccount, announcedActivity, audience)
|
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendVideoAnnounceToFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
|
|
|
const data = await buildVideoAnnounceToFollowers(byAccount, video, t)
|
|
|
|
|
2017-11-20 03:43:39 -05:00
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
2017-11-27 08:44:51 -05:00
|
|
|
async function sendVideoAnnounceToOrigin (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 accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
|
|
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
|
|
|
const data = await createActivityData(url, byAccount, announcedActivity, audience)
|
|
|
|
|
|
|
|
return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function buildVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
|
2017-11-20 03:43:39 -05:00
|
|
|
const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
|
|
|
|
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject())
|
|
|
|
|
2017-11-27 08:44:51 -05:00
|
|
|
const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel)
|
|
|
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
|
|
|
const data = await announceActivityData(url, byAccount, announcedActivity, audience)
|
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
async function sendVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
|
|
|
|
const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t)
|
|
|
|
|
2017-11-20 03:43:39 -05:00
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
2017-11-27 08:44:51 -05:00
|
|
|
async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
|
|
|
|
const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
|
|
|
|
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject())
|
|
|
|
|
|
|
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel)
|
|
|
|
const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo)
|
|
|
|
const data = await createActivityData(url, byAccount, announcedActivity, audience)
|
|
|
|
|
|
|
|
return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function announceActivityData (
|
|
|
|
url: string,
|
|
|
|
byAccount: AccountInstance,
|
|
|
|
object: ActivityCreate | ActivityAdd,
|
|
|
|
audience?: ActivityAudience
|
|
|
|
) {
|
|
|
|
if (!audience) {
|
|
|
|
audience = await getAudience(byAccount)
|
|
|
|
}
|
|
|
|
|
2017-11-21 12:23:10 -05:00
|
|
|
const activity: ActivityAnnounce = {
|
2017-11-20 03:43:39 -05:00
|
|
|
type: 'Announce',
|
2017-11-27 08:44:51 -05:00
|
|
|
to: audience.to,
|
|
|
|
cc: audience.cc,
|
2017-11-20 03:43:39 -05:00
|
|
|
id: url,
|
|
|
|
actor: byAccount.url,
|
|
|
|
object
|
|
|
|
}
|
|
|
|
|
|
|
|
return activity
|
|
|
|
}
|
2017-11-21 12:23:10 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2017-11-27 08:44:51 -05:00
|
|
|
sendVideoAnnounceToFollowers,
|
|
|
|
sendVideoChannelAnnounceToFollowers,
|
|
|
|
sendVideoAnnounceToOrigin,
|
|
|
|
sendVideoChannelAnnounceToOrigin,
|
|
|
|
announceActivityData,
|
|
|
|
buildVideoAnnounceToFollowers,
|
|
|
|
buildVideoChannelAnnounceToFollowers
|
2017-11-21 12:23:10 -05:00
|
|
|
}
|