PeerTube/server/lib/activitypub/send/send-view.ts

43 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Transaction } from 'sequelize'
import { VideoViews } from '@server/lib/video-views'
2020-11-20 11:21:08 +01:00
import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models'
import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub'
2020-11-20 11:21:08 +01:00
import { logger } from '../../../helpers/logger'
2021-05-11 11:15:29 +02:00
import { ActorModel } from '../../../models/actor/actor'
import { audiencify, getAudience } from '../audience'
2020-11-20 11:21:08 +01:00
import { getLocalVideoViewActivityPubUrl } from '../url'
import { sendVideoRelatedActivity } from './utils'
2020-02-04 16:14:33 +01:00
async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) {
logger.info('Creating job to send view of %s.', video.url)
const activityBuilder = (audience: ActivityAudience) => {
2020-11-20 11:21:08 +01:00
const url = getLocalVideoViewActivityPubUrl(byActor, video)
return buildViewActivity(url, byActor, video, audience)
}
return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t, contextType: 'View' })
}
2019-08-15 11:53:26 +02:00
function buildViewActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityView {
if (!audience) audience = getAudience(byActor)
return audiencify(
{
id: url,
type: 'View' as 'View',
actor: byActor.url,
object: video.url,
expires: new Date(VideoViews.Instance.buildViewerExpireTime()).toISOString()
},
audience
)
}
// ---------------------------------------------------------------------------
export {
sendView
}