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-12-12 10:53:50 -06:00
|
|
|
import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub'
|
|
|
|
import { AccountModel } from '../../../models/account/account'
|
|
|
|
import { VideoModel } from '../../../models/video/video'
|
|
|
|
import { VideoChannelModel } from '../../../models/video/video-channel'
|
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-12-12 10:53:50 -06:00
|
|
|
async function buildVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, 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-12-12 10:53:50 -06:00
|
|
|
return announceActivityData(url, byAccount, announcedActivity, t, audience)
|
2017-11-27 07:44:51 -06:00
|
|
|
}
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
async function sendVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
|
2017-11-27 07:44:51 -06:00
|
|
|
const data = await buildVideoAnnounceToFollowers(byAccount, video, t)
|
|
|
|
|
2017-11-20 02:43:39 -06:00
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
async function sendVideoAnnounceToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) {
|
2017-11-27 07:44:51 -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-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)
|
|
|
|
}
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
async function buildVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, 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-12-12 10:53:50 -06:00
|
|
|
return announceActivityData(url, byAccount, announcedActivity, t, audience)
|
2017-11-27 07:44:51 -06:00
|
|
|
}
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
async function sendVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) {
|
2017-11-27 07:44:51 -06:00
|
|
|
const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t)
|
|
|
|
|
2017-11-20 02:43:39 -06:00
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
async function sendVideoChannelAnnounceToOrigin (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) {
|
2017-11-27 07:44:51 -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-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,
|
2017-12-12 10:53:50 -06:00
|
|
|
byAccount: AccountModel,
|
2017-11-27 07:44:51 -06:00
|
|
|
object: ActivityCreate | ActivityAdd,
|
2017-11-30 04:31:15 -06:00
|
|
|
t: Transaction,
|
2017-11-27 07:44:51 -06:00
|
|
|
audience?: ActivityAudience
|
2017-12-12 10:53:50 -06:00
|
|
|
): Promise<ActivityAnnounce> {
|
2017-11-27 07:44:51 -06:00
|
|
|
if (!audience) {
|
2017-11-30 04:31:15 -06:00
|
|
|
audience = await getAudience(byAccount, t)
|
2017-11-27 07:44:51 -06:00
|
|
|
}
|
|
|
|
|
2017-12-12 10:53:50 -06:00
|
|
|
return {
|
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
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|