]>
Commit | Line | Data |
---|---|---|
1e7eb25f | 1 | import { Transaction } from 'sequelize' |
de94ac86 | 2 | import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models' |
1e7eb25f | 3 | import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub' |
de94ac86 | 4 | import { logger } from '../../../helpers/logger' |
1e7eb25f | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
1e7eb25f | 6 | import { audiencify, getAudience } from '../audience' |
de94ac86 C |
7 | import { getLocalVideoViewActivityPubUrl } from '../url' |
8 | import { sendVideoRelatedActivity } from './utils' | |
1e7eb25f | 9 | |
2c8776fc | 10 | async 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 | 22 | function 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 | ||
38 | export { | |
39 | sendView | |
40 | } |