2017-11-20 09:43:39 +01:00
|
|
|
import { Transaction } from 'sequelize'
|
2018-01-26 12:02:18 +01:00
|
|
|
import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
|
2017-12-14 17:38:41 +01:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
2017-12-12 17:53:50 +01:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2018-01-26 15:49:57 +01:00
|
|
|
import { VideoShareModel } from '../../../models/video/video-share'
|
|
|
|
import { broadcastToFollowers, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from './misc'
|
2017-11-20 09:43:39 +01:00
|
|
|
|
2018-03-27 13:33:56 +02:00
|
|
|
async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
2018-01-26 12:02:18 +01:00
|
|
|
const announcedObject = video.url
|
2017-11-20 09:43:39 +01:00
|
|
|
|
2017-12-14 17:38:41 +01:00
|
|
|
const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
|
2017-11-27 14:44:51 +01:00
|
|
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
2018-01-26 15:49:57 +01:00
|
|
|
return announceActivityData(videoShare.url, byActor, announcedObject, t, audience)
|
2017-11-27 14:44:51 +01:00
|
|
|
}
|
|
|
|
|
2018-03-27 13:33:56 +02:00
|
|
|
async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
|
|
|
const data = await buildVideoAnnounce(byActor, videoShare, video, t)
|
2017-11-27 14:44:51 +01:00
|
|
|
|
2017-12-14 17:38:41 +01:00
|
|
|
return broadcastToFollowers(data, byActor, [ byActor ], t)
|
2017-11-20 09:43:39 +01:00
|
|
|
}
|
|
|
|
|
2017-11-27 14:44:51 +01:00
|
|
|
async function announceActivityData (
|
|
|
|
url: string,
|
2017-12-14 17:38:41 +01:00
|
|
|
byActor: ActorModel,
|
2018-01-26 12:02:18 +01:00
|
|
|
object: string,
|
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-12-14 17:38:41 +01:00
|
|
|
audience = await getAudience(byActor, 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,
|
2017-12-14 17:38:41 +01:00
|
|
|
actor: byActor.url,
|
2017-11-20 09:43:39 +01:00
|
|
|
object
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 18:23:10 +01:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-03-27 13:33:56 +02:00
|
|
|
sendVideoAnnounce,
|
2017-11-27 14:44:51 +01:00
|
|
|
announceActivityData,
|
2018-03-27 13:33:56 +02:00
|
|
|
buildVideoAnnounce
|
2017-11-21 18:23:10 +01:00
|
|
|
}
|