]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-announce.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-announce.ts
CommitLineData
54141398 1import { Transaction } from 'sequelize'
7acee6f1 2import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
e251f170 3import { broadcastToFollowers } from './utils'
a2377d15 4import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf } from '../audience'
8e0fd45e 5import { logger } from '../../../helpers/logger'
453e83ea
C
6import { MActorLight, MVideo } from '../../../typings/models'
7import { MVideoShare } from '../../../typings/models/video'
5224c394
C
8
9async 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 25async 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 34function 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
47export {
07197db4 48 sendVideoAnnounce,
c48e82b5
C
49 buildAnnounceActivity,
50 buildAnnounceWithVideoAudience
e71bcc0f 51}