2019-01-15 07:52:33 -06:00
|
|
|
import { Transaction } from 'sequelize'
|
2022-03-24 07:36:47 -05:00
|
|
|
import { VideoViewsManager } from '@server/lib/views/video-views-manager'
|
|
|
|
import { MActorAudience, MActorLight, MVideoImmutable, MVideoUrl } from '@server/types/models'
|
2022-03-18 05:17:35 -05:00
|
|
|
import { ActivityAudience, ActivityView } from '@shared/models'
|
2020-11-20 04:21:08 -06:00
|
|
|
import { logger } from '../../../helpers/logger'
|
2019-01-15 07:52:33 -06:00
|
|
|
import { audiencify, getAudience } from '../audience'
|
2020-11-20 04:21:08 -06:00
|
|
|
import { getLocalVideoViewActivityPubUrl } from '../url'
|
2022-03-18 05:17:35 -05:00
|
|
|
import { sendVideoRelatedActivity } from './shared/send-utils'
|
2019-01-15 07:52:33 -06:00
|
|
|
|
2022-03-24 07:36:47 -05:00
|
|
|
type ViewType = 'view' | 'viewer'
|
|
|
|
|
|
|
|
async function sendView (options: {
|
|
|
|
byActor: MActorLight
|
|
|
|
type: ViewType
|
|
|
|
video: MVideoImmutable
|
|
|
|
transaction?: Transaction
|
|
|
|
}) {
|
|
|
|
const { byActor, type, video, transaction } = options
|
|
|
|
|
|
|
|
logger.info('Creating job to send %s of %s.', type, video.url)
|
2019-01-15 07:52:33 -06:00
|
|
|
|
|
|
|
const activityBuilder = (audience: ActivityAudience) => {
|
2020-11-20 04:21:08 -06:00
|
|
|
const url = getLocalVideoViewActivityPubUrl(byActor, video)
|
2019-01-15 07:52:33 -06:00
|
|
|
|
2022-03-24 07:36:47 -05:00
|
|
|
return buildViewActivity({ url, byActor, video, audience, type })
|
2019-01-15 07:52:33 -06:00
|
|
|
}
|
|
|
|
|
2022-03-24 07:36:47 -05:00
|
|
|
return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction, contextType: 'View' })
|
2019-01-15 07:52:33 -06:00
|
|
|
}
|
|
|
|
|
2022-03-24 07:36:47 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendView
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function buildViewActivity (options: {
|
|
|
|
url: string
|
|
|
|
byActor: MActorAudience
|
|
|
|
video: MVideoUrl
|
|
|
|
type: ViewType
|
|
|
|
audience?: ActivityAudience
|
|
|
|
}): ActivityView {
|
|
|
|
const { url, byActor, type, video, audience = getAudience(byActor) } = options
|
2019-01-15 07:52:33 -06:00
|
|
|
|
|
|
|
return audiencify(
|
|
|
|
{
|
|
|
|
id: url,
|
|
|
|
type: 'View' as 'View',
|
|
|
|
actor: byActor.url,
|
2021-11-09 03:11:20 -06:00
|
|
|
object: video.url,
|
2022-03-24 07:36:47 -05:00
|
|
|
|
|
|
|
expires: type === 'viewer'
|
|
|
|
? new Date(VideoViewsManager.Instance.buildViewerExpireTime()).toISOString()
|
|
|
|
: undefined
|
2019-01-15 07:52:33 -06:00
|
|
|
},
|
|
|
|
audience
|
|
|
|
)
|
|
|
|
}
|