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