2017-11-20 08:43:39 +00:00
|
|
|
import { Transaction } from 'sequelize'
|
2018-01-26 11:02:18 +00:00
|
|
|
import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
|
2017-12-14 16:38:41 +00:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
2017-12-12 16:53:50 +00:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2017-11-21 17:23:10 +00:00
|
|
|
import { getAnnounceActivityPubUrl } from '../url'
|
2017-11-27 13:44:51 +00:00
|
|
|
import {
|
|
|
|
broadcastToFollowers,
|
2017-12-14 16:38:41 +00:00
|
|
|
getActorsInvolvedInVideo,
|
2017-11-27 13:44:51 +00:00
|
|
|
getAudience,
|
|
|
|
getObjectFollowersAudience,
|
|
|
|
getOriginVideoAudience,
|
|
|
|
unicastTo
|
|
|
|
} from './misc'
|
2017-11-20 08:43:39 +00:00
|
|
|
import { createActivityData } from './send-create'
|
|
|
|
|
2017-12-14 16:38:41 +00:00
|
|
|
async function buildVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
|
|
|
const url = getAnnounceActivityPubUrl(video.url, byActor)
|
2018-01-26 11:02:18 +00:00
|
|
|
const announcedObject = video.url
|
2017-11-20 08:43:39 +00:00
|
|
|
|
2017-12-14 16:38:41 +00:00
|
|
|
const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
|
2017-11-27 13:44:51 +00:00
|
|
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
2018-01-26 11:02:18 +00:00
|
|
|
return announceActivityData(url, byActor, announcedObject, t, audience)
|
2017-11-27 13:44:51 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 16:38:41 +00:00
|
|
|
async function sendVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
|
|
|
const data = await buildVideoAnnounceToFollowers(byActor, video, t)
|
2017-11-27 13:44:51 +00:00
|
|
|
|
2017-12-14 16:38:41 +00:00
|
|
|
return broadcastToFollowers(data, byActor, [ byActor ], t)
|
2017-11-20 08:43:39 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 16:38:41 +00:00
|
|
|
async function sendVideoAnnounceToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
|
|
|
const url = getAnnounceActivityPubUrl(video.url, byActor)
|
2017-11-27 13:44:51 +00:00
|
|
|
|
2017-12-14 16:38:41 +00:00
|
|
|
const videoObject = video.toActivityPubObject()
|
|
|
|
const announcedActivity = await createActivityData(url, video.VideoChannel.Account.Actor, videoObject, t)
|
2017-11-27 13:44:51 +00:00
|
|
|
|
2017-12-14 16:38:41 +00:00
|
|
|
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
|
|
|
const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
|
|
|
|
const data = await createActivityData(url, byActor, announcedActivity, t, audience)
|
2017-11-27 13:44:51 +00:00
|
|
|
|
2018-01-25 14:05:18 +00:00
|
|
|
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
2017-11-27 13:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function announceActivityData (
|
|
|
|
url: string,
|
2017-12-14 16:38:41 +00:00
|
|
|
byActor: ActorModel,
|
2018-01-26 11:02:18 +00:00
|
|
|
object: string,
|
2017-11-30 10:31:15 +00:00
|
|
|
t: Transaction,
|
2017-11-27 13:44:51 +00:00
|
|
|
audience?: ActivityAudience
|
2017-12-12 16:53:50 +00:00
|
|
|
): Promise<ActivityAnnounce> {
|
2017-11-27 13:44:51 +00:00
|
|
|
if (!audience) {
|
2017-12-14 16:38:41 +00:00
|
|
|
audience = await getAudience(byActor, t)
|
2017-11-27 13:44:51 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 16:53:50 +00:00
|
|
|
return {
|
2017-11-20 08:43:39 +00:00
|
|
|
type: 'Announce',
|
2017-11-27 13:44:51 +00:00
|
|
|
to: audience.to,
|
|
|
|
cc: audience.cc,
|
2017-11-20 08:43:39 +00:00
|
|
|
id: url,
|
2017-12-14 16:38:41 +00:00
|
|
|
actor: byActor.url,
|
2017-11-20 08:43:39 +00:00
|
|
|
object
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 17:23:10 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2017-11-27 13:44:51 +00:00
|
|
|
sendVideoAnnounceToFollowers,
|
|
|
|
sendVideoAnnounceToOrigin,
|
|
|
|
announceActivityData,
|
2017-12-14 16:38:41 +00:00
|
|
|
buildVideoAnnounceToFollowers
|
2017-11-21 17:23:10 +00:00
|
|
|
}
|