]>
Commit | Line | Data |
---|---|---|
1e7eb25f | 1 | import { Transaction } from 'sequelize' |
b2111066 C |
2 | import { VideoViewsManager } from '@server/lib/views/video-views-manager' |
3 | import { MActorAudience, MActorLight, MVideoImmutable, MVideoUrl } from '@server/types/models' | |
57e4e1c1 | 4 | import { ActivityAudience, ActivityView } from '@shared/models' |
de94ac86 | 5 | import { logger } from '../../../helpers/logger' |
1e7eb25f | 6 | import { audiencify, getAudience } from '../audience' |
de94ac86 | 7 | import { getLocalVideoViewActivityPubUrl } from '../url' |
57e4e1c1 | 8 | import { sendVideoRelatedActivity } from './shared/send-utils' |
1e7eb25f | 9 | |
b2111066 C |
10 | type ViewType = 'view' | 'viewer' |
11 | ||
12 | async function sendView (options: { | |
13 | byActor: MActorLight | |
14 | type: ViewType | |
15 | video: MVideoImmutable | |
ac907dc7 | 16 | viewerIdentifier: string |
b2111066 C |
17 | transaction?: Transaction |
18 | }) { | |
ac907dc7 | 19 | const { byActor, type, video, viewerIdentifier, transaction } = options |
b2111066 C |
20 | |
21 | logger.info('Creating job to send %s of %s.', type, video.url) | |
1e7eb25f C |
22 | |
23 | const activityBuilder = (audience: ActivityAudience) => { | |
ac907dc7 | 24 | const url = getLocalVideoViewActivityPubUrl(byActor, video, viewerIdentifier) |
1e7eb25f | 25 | |
b2111066 | 26 | return buildViewActivity({ url, byActor, video, audience, type }) |
1e7eb25f C |
27 | } |
28 | ||
f27b7a75 | 29 | return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction, contextType: 'View', parallelizable: true }) |
1e7eb25f C |
30 | } |
31 | ||
b2111066 C |
32 | // --------------------------------------------------------------------------- |
33 | ||
34 | export { | |
35 | sendView | |
36 | } | |
37 | ||
38 | // --------------------------------------------------------------------------- | |
39 | ||
40 | function buildViewActivity (options: { | |
41 | url: string | |
42 | byActor: MActorAudience | |
43 | video: MVideoUrl | |
44 | type: ViewType | |
45 | audience?: ActivityAudience | |
46 | }): ActivityView { | |
47 | const { url, byActor, type, video, audience = getAudience(byActor) } = options | |
1e7eb25f C |
48 | |
49 | return audiencify( | |
50 | { | |
51 | id: url, | |
52 | type: 'View' as 'View', | |
53 | actor: byActor.url, | |
51353d9a | 54 | object: video.url, |
b2111066 C |
55 | |
56 | expires: type === 'viewer' | |
57 | ? new Date(VideoViewsManager.Instance.buildViewerExpireTime()).toISOString() | |
58 | : undefined | |
1e7eb25f C |
59 | }, |
60 | audience | |
61 | ) | |
62 | } |