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