]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-announce.ts
Prevent duplicated HLS playlist on transcoding
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-announce.ts
CommitLineData
54141398 1import { Transaction } from 'sequelize'
57e4e1c1 2import { ActivityAnnounce, ActivityAudience } from '@shared/models'
8e0fd45e 3import { logger } from '../../../helpers/logger'
26d6bf65
C
4import { MActorLight, MVideo } from '../../../types/models'
5import { MVideoShare } from '../../../types/models/video'
57e4e1c1
C
6import { audiencify, getAudience } from '../audience'
7import { getActorsInvolvedInVideo, getAudienceFromFollowersOf } from './shared'
8import { broadcastToFollowers } from './shared/send-utils'
5224c394
C
9
10async function buildAnnounceWithVideoAudience (
453e83ea
C
11 byActor: MActorLight,
12 videoShare: MVideoShare,
13 video: MVideo,
5224c394
C
14 t: Transaction
15) {
7acee6f1 16 const announcedObject = video.url
54141398 17
c48e82b5 18 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
a2377d15 19 const audience = getAudienceFromFollowersOf(actorsInvolvedInVideo)
c48e82b5
C
20
21 const activity = buildAnnounceActivity(videoShare.url, byActor, announcedObject, audience)
22
23 return { activity, actorsInvolvedInVideo }
4e50b6a1
C
24}
25
a219c910
C
26async function sendVideoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, transaction: Transaction) {
27 const { activity, actorsInvolvedInVideo } = await buildAnnounceWithVideoAudience(byActor, videoShare, video, transaction)
4e50b6a1 28
8e0fd45e
C
29 logger.info('Creating job to send announce %s.', videoShare.url)
30
a219c910
C
31 return broadcastToFollowers({
32 data: activity,
33 byActor,
34 toFollowersOf: actorsInvolvedInVideo,
35 transaction,
36 actorsException: [ byActor ],
37 contextType: 'Announce'
38 })
54141398
C
39}
40
453e83ea 41function buildAnnounceActivity (url: string, byActor: MActorLight, object: string, audience?: ActivityAudience): ActivityAnnounce {
2186386c 42 if (!audience) audience = getAudience(byActor)
4e50b6a1 43
c48e82b5
C
44 return audiencify({
45 type: 'Announce' as 'Announce',
54141398 46 id: url,
50d6de9c 47 actor: byActor.url,
54141398 48 object
c48e82b5 49 }, audience)
54141398 50}
e71bcc0f
C
51
52// ---------------------------------------------------------------------------
53
54export {
07197db4 55 sendVideoAnnounce,
c48e82b5
C
56 buildAnnounceActivity,
57 buildAnnounceWithVideoAudience
e71bcc0f 58}