2019-01-15 14:52:33 +01:00
|
|
|
import { Transaction } from 'sequelize'
|
|
|
|
import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub'
|
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
|
|
|
import { getVideoLikeActivityPubUrl } from '../url'
|
|
|
|
import { sendVideoRelatedActivity } from './utils'
|
|
|
|
import { audiencify, getAudience } from '../audience'
|
|
|
|
import { logger } from '../../../helpers/logger'
|
2020-02-04 16:14:33 +01:00
|
|
|
import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/typings/models'
|
2019-01-15 14:52:33 +01:00
|
|
|
|
2020-02-04 16:14:33 +01:00
|
|
|
async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) {
|
2019-01-15 14:52:33 +01:00
|
|
|
logger.info('Creating job to send view of %s.', video.url)
|
|
|
|
|
|
|
|
const activityBuilder = (audience: ActivityAudience) => {
|
|
|
|
const url = getVideoLikeActivityPubUrl(byActor, video)
|
|
|
|
|
|
|
|
return buildViewActivity(url, byActor, video, audience)
|
|
|
|
}
|
|
|
|
|
2020-02-03 11:12:29 +01:00
|
|
|
return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t, contextType: 'View' })
|
2019-01-15 14:52:33 +01:00
|
|
|
}
|
|
|
|
|
2019-08-15 11:53:26 +02:00
|
|
|
function buildViewActivity (url: string, byActor: MActorAudience, video: MVideoUrl, audience?: ActivityAudience): ActivityView {
|
2019-01-15 14:52:33 +01:00
|
|
|
if (!audience) audience = getAudience(byActor)
|
|
|
|
|
|
|
|
return audiencify(
|
|
|
|
{
|
|
|
|
id: url,
|
|
|
|
type: 'View' as 'View',
|
|
|
|
actor: byActor.url,
|
|
|
|
object: video.url
|
|
|
|
},
|
|
|
|
audience
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
sendView
|
|
|
|
}
|