]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/send/send-announce.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-announce.ts
... / ...
CommitLineData
1import { Transaction } from 'sequelize'
2import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
3import { broadcastToFollowers } from './utils'
4import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf } from '../audience'
5import { logger } from '../../../helpers/logger'
6import { MActorLight, MVideo } from '../../../typings/models'
7import { MVideoShare } from '../../../typings/models/video'
8
9async function buildAnnounceWithVideoAudience (
10 byActor: MActorLight,
11 videoShare: MVideoShare,
12 video: MVideo,
13 t: Transaction
14) {
15 const announcedObject = video.url
16
17 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
18 const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
19
20 const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience)
21
22 return { activity, actorsInvolvedInVideo }
23}
24
25async function sendVideoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, t: Transaction) {
26 const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, t)
27
28 logger.info('Creating job to send announce %s.', videoShare.url)
29
30 const followersException = [ byActor ]
31 return broadcastToFollowers(activity, byActor, actorsInvolvedInVideo, t, followersException, 'Announce')
32}
33
34function buildAnnounceActivity (url: string, byActor: MActorLight, object: string, audience?: ActivityAudience): ActivityAnnounce {
35 if (!audience) audience = getAudience(byActor)
36
37 return audiencify({
38 type: 'Announce' as 'Announce',
39 id: url,
40 actor: byActor.url,
41 object
42 }, audience)
43}
44
45// ---------------------------------------------------------------------------
46
47export {
48 sendVideoAnnounce,
49 buildAnnounceActivity,
50 buildAnnounceWithVideoAudience
51}