1 import { Transaction } from 'sequelize'
2 import { VideoViewsManager } from '@server/lib/views/video-views-manager'
3 import { MActorAudience, MActorLight, MVideoImmutable, MVideoUrl } from '@server/types/models'
4 import { ActivityAudience, ActivityView } from '@shared/models'
5 import { logger } from '../../../helpers/logger'
6 import { audiencify, getAudience } from '../audience'
7 import { getLocalVideoViewActivityPubUrl } from '../url'
8 import { sendVideoRelatedActivity } from './shared/send-utils'
10 type ViewType = 'view' | 'viewer'
12 async function sendView (options: {
15 video: MVideoImmutable
16 viewerIdentifier: string
17 transaction?: Transaction
19 const { byActor, type, video, viewerIdentifier, transaction } = options
21 logger.info('Creating job to send %s of %s.', type, video.url)
23 const activityBuilder = (audience: ActivityAudience) => {
24 const url = getLocalVideoViewActivityPubUrl(byActor, video, viewerIdentifier)
26 return buildViewActivity({ url, byActor, video, audience, type })
29 return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction, contextType: 'View', parallelizable: true })
32 // ---------------------------------------------------------------------------
38 // ---------------------------------------------------------------------------
40 function buildViewActivity (options: {
42 byActor: MActorAudience
45 audience?: ActivityAudience
47 const { url, byActor, type, video, audience = getAudience(byActor) } = options
52 type: 'View' as 'View',
56 expires: type === 'viewer'
57 ? new Date(VideoViewsManager.Instance.buildViewerExpireTime()).toISOString()