2017-11-20 09:43:39 +01:00
|
|
|
import { Transaction } from 'sequelize'
|
2017-11-21 18:23:10 +01:00
|
|
|
import { ActivityAdd } from '../../../../shared/index'
|
2017-12-12 17:53:50 +01: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 18:23:10 +01:00
|
|
|
import { getAnnounceActivityPubUrl } from '../url'
|
2017-11-27 14:44:51 +01:00
|
|
|
import {
|
|
|
|
broadcastToFollowers,
|
|
|
|
getAccountsInvolvedInVideo,
|
|
|
|
getAccountsInvolvedInVideoChannel,
|
|
|
|
getAudience,
|
|
|
|
getObjectFollowersAudience,
|
|
|
|
getOriginVideoAudience,
|
|
|
|
getOriginVideoChannelAudience,
|
|
|
|
unicastTo
|
|
|
|
} from './misc'
|
2017-11-20 09:43:39 +01:00
|
|
|
import { addActivityData } from './send-add'
|
|
|
|
import { createActivityData } from './send-create'
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
async function buildVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
|
2017-11-20 09:43:39 +01:00
|
|
|
const url = getAnnounceActivityPubUrl(video.url, byAccount)
|
|
|
|
|
|
|
|
const videoChannel = video.VideoChannel
|
2017-11-30 11:31:15 +01:00
|
|
|
const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t)
|
2017-11-20 09:43:39 +01:00
|
|
|
|
2017-11-30 11:31:15 +01:00
|
|
|
const accountsToForwardView = await getAccountsInvolvedInVideo(video, t)
|
2017-11-27 14:44:51 +01:00
|
|
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
2017-12-12 17:53:50 +01:00
|
|
|
return announceActivityData(url, byAccount, announcedActivity, t, audience)
|
2017-11-27 14:44:51 +01:00
|
|
|
}
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
async function sendVideoAnnounceToFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
|
2017-11-27 14:44:51 +01:00
|
|
|
const data = await buildVideoAnnounceToFollowers(byAccount, video, t)
|
|
|
|
|
2017-11-20 09:43:39 +01:00
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
async function sendVideoAnnounceToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) {
|
2017-11-27 14:44:51 +01:00
|
|
|
const url = getAnnounceActivityPubUrl(video.url, byAccount)
|
|
|
|
|
|
|
|
const videoChannel = video.VideoChannel
|
2017-11-30 11:31:15 +01:00
|
|
|
const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t)
|
2017-11-27 14:44:51 +01:00
|
|
|
|
2017-11-30 11:31:15 +01:00
|
|
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
2017-11-27 14:44:51 +01:00
|
|
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
2017-11-30 11:31:15 +01:00
|
|
|
const data = await createActivityData(url, byAccount, announcedActivity, t, audience)
|
2017-11-27 14:44:51 +01:00
|
|
|
|
|
|
|
return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
async function buildVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) {
|
2017-11-20 09:43:39 +01:00
|
|
|
const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
|
2017-11-30 11:31:15 +01:00
|
|
|
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t)
|
2017-11-20 09:43:39 +01:00
|
|
|
|
2017-11-30 11:31:15 +01:00
|
|
|
const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t)
|
2017-11-27 14:44:51 +01:00
|
|
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
2017-12-12 17:53:50 +01:00
|
|
|
return announceActivityData(url, byAccount, announcedActivity, t, audience)
|
2017-11-27 14:44:51 +01:00
|
|
|
}
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
async function sendVideoChannelAnnounceToFollowers (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) {
|
2017-11-27 14:44:51 +01:00
|
|
|
const data = await buildVideoChannelAnnounceToFollowers(byAccount, videoChannel, t)
|
|
|
|
|
2017-11-20 09:43:39 +01:00
|
|
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
|
|
|
}
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
async function sendVideoChannelAnnounceToOrigin (byAccount: AccountModel, videoChannel: VideoChannelModel, t: Transaction) {
|
2017-11-27 14:44:51 +01:00
|
|
|
const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
|
2017-11-30 11:31:15 +01:00
|
|
|
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t)
|
2017-11-27 14:44:51 +01:00
|
|
|
|
2017-11-30 11:31:15 +01:00
|
|
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel, t)
|
2017-11-27 14:44:51 +01:00
|
|
|
const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo)
|
2017-11-30 11:31:15 +01:00
|
|
|
const data = await createActivityData(url, byAccount, announcedActivity, t, audience)
|
2017-11-27 14:44:51 +01:00
|
|
|
|
|
|
|
return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function announceActivityData (
|
|
|
|
url: string,
|
2017-12-12 17:53:50 +01:00
|
|
|
byAccount: AccountModel,
|
2017-11-27 14:44:51 +01:00
|
|
|
object: ActivityCreate | ActivityAdd,
|
2017-11-30 11:31:15 +01:00
|
|
|
t: Transaction,
|
2017-11-27 14:44:51 +01:00
|
|
|
audience?: ActivityAudience
|
2017-12-12 17:53:50 +01:00
|
|
|
): Promise<ActivityAnnounce> {
|
2017-11-27 14:44:51 +01:00
|
|
|
if (!audience) {
|
2017-11-30 11:31:15 +01:00
|
|
|
audience = await getAudience(byAccount, t)
|
2017-11-27 14:44:51 +01:00
|
|
|
}
|
|
|
|
|
2017-12-12 17:53:50 +01:00
|
|
|
return {
|
2017-11-20 09:43:39 +01:00
|
|
|
type: 'Announce',
|
2017-11-27 14:44:51 +01:00
|
|
|
to: audience.to,
|
|
|
|
cc: audience.cc,
|
2017-11-20 09:43:39 +01:00
|
|
|
id: url,
|
|
|
|
actor: byAccount.url,
|
|
|
|
object
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 18:23:10 +01:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2017-11-27 14:44:51 +01:00
|
|
|
sendVideoAnnounceToFollowers,
|
|
|
|
sendVideoChannelAnnounceToFollowers,
|
|
|
|
sendVideoAnnounceToOrigin,
|
|
|
|
sendVideoChannelAnnounceToOrigin,
|
|
|
|
announceActivityData,
|
|
|
|
buildVideoAnnounceToFollowers,
|
|
|
|
buildVideoChannelAnnounceToFollowers
|
2017-11-21 18:23:10 +01:00
|
|
|
}
|