1 import { Transaction } from 'sequelize'
2 import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
3 import { broadcastToFollowers } from './utils'
4 import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf } from '../audience'
5 import { logger } from '../../../helpers/logger'
6 import { MActorLight, MVideo } from '../../../types/models'
7 import { MVideoShare } from '../../../types/models/video'
9 async function buildAnnounceWithVideoAudience (
11 videoShare: MVideoShare,
15 const announcedObject = video.url
17 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
18 const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
20 const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience)
22 return { activity, actorsInvolvedInVideo }
25 async function sendVideoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, t: Transaction) {
26 const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t)
28 logger.info('Creating job to send announce %s.', videoShare.url)
30 const followersException = [ byActor ]
31 return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, t, followersException, 'Announce')
34 function buildAnnounceActivity (url: string, byActor: MActorLight, object: string, audience?: ActivityAudience): ActivityAnnounce {
35 if (!audience) audience = getAudience(byActor)
38 type: 'Announce' as 'Announce',
45 // ---------------------------------------------------------------------------
49 buildAnnounceActivity,
50 buildAnnounceWithVideoAudience