]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/send/send-view.ts
Fix incorrect IDs in AP federation
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-view.ts
CommitLineData
1e7eb25f 1import { Transaction } from 'sequelize'
de94ac86 2import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models'
1e7eb25f 3import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub'
de94ac86 4import { logger } from '../../../helpers/logger'
1e7eb25f 5import { ActorModel } from '../../../models/activitypub/actor'
1e7eb25f 6import { audiencify, getAudience } from '../audience'
de94ac86
C
7import { getLocalVideoViewActivityPubUrl } from '../url'
8import { sendVideoRelatedActivity } from './utils'
1e7eb25f 9
2c8776fc 10async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) {
1e7eb25f
C
11 logger.info('Creating job to send view of %s.', video.url)
12
13 const activityBuilder = (audience: ActivityAudience) => {
de94ac86 14 const url = getLocalVideoViewActivityPubUrl(byActor, video)
1e7eb25f
C
15
16 return buildViewActivity(url, byActor, video, audience)
17 }
18
598edb8a 19 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t, contextType: 'View' })
1e7eb25f
C
20}
21
453e83ea 22function buildViewActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityView {
1e7eb25f
C
23 if (!audience) audience = getAudience(byActor)
24
25 return audiencify(
26 {
27 id: url,
28 type: 'View' as 'View',
29 actor: byActor.url,
30 object: video.url
31 },
32 audience
33 )
34}
35
36// ---------------------------------------------------------------------------
37
38export {
39 sendView
40}