]>
Commit | Line | Data |
---|---|---|
54141398 | 1 | import { Transaction } from 'sequelize' |
7acee6f1 | 2 | import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub' |
e251f170 | 3 | import { broadcastToFollowers } from './utils' |
a2377d15 | 4 | import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf } from '../audience' |
8e0fd45e | 5 | import { logger } from '../../../helpers/logger' |
26d6bf65 C |
6 | import { MActorLight, MVideo } from '../../../types/models' |
7 | import { MVideoShare } from '../../../types/models/video' | |
5224c394 C |
8 | |
9 | async function buildAnnounceWithVideoAudience ( | |
453e83ea C |
10 | byActor: MActorLight, |
11 | videoShare: MVideoShare, | |
12 | video: MVideo, | |
5224c394 C |
13 | t: Transaction |
14 | ) { | |
7acee6f1 | 15 | const announcedObject = video.url |
54141398 | 16 | |
c48e82b5 | 17 | const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) |
a2377d15 | 18 | const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo) |
c48e82b5 C |
19 | |
20 | const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience) | |
21 | ||
22 | return { activity, actorsInvolvedInVideo } | |
4e50b6a1 C |
23 | } |
24 | ||
453e83ea | 25 | async function sendVideoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, t: Transaction) { |
c48e82b5 | 26 | const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t) |
4e50b6a1 | 27 | |
8e0fd45e C |
28 | logger.info('Creating job to send announce %s.', videoShare.url) |
29 | ||
5cf84858 | 30 | const followersException = [ byActor ] |
598edb8a | 31 | return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, t, followersException, 'Announce') |
54141398 C |
32 | } |
33 | ||
453e83ea | 34 | function buildAnnounceActivity (url: string, byActor: MActorLight, object: string, audience?: ActivityAudience): ActivityAnnounce { |
2186386c | 35 | if (!audience) audience = getAudience(byActor) |
4e50b6a1 | 36 | |
c48e82b5 C |
37 | return audiencify({ |
38 | type: 'Announce' as 'Announce', | |
54141398 | 39 | id: url, |
50d6de9c | 40 | actor: byActor.url, |
54141398 | 41 | object |
c48e82b5 | 42 | }, audience) |
54141398 | 43 | } |
e71bcc0f C |
44 | |
45 | // --------------------------------------------------------------------------- | |
46 | ||
47 | export { | |
07197db4 | 48 | sendVideoAnnounce, |
c48e82b5 C |
49 | buildAnnounceActivity, |
50 | buildAnnounceWithVideoAudience | |
e71bcc0f | 51 | } |