send-view.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Transaction } from 'sequelize'
  2. import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub'
  3. import { ActorModel } from '../../../models/activitypub/actor'
  4. import { VideoModel } from '../../../models/video/video'
  5. import { getVideoLikeActivityPubUrl } from '../url'
  6. import { sendVideoRelatedActivity } from './utils'
  7. import { audiencify, getAudience } from '../audience'
  8. import { logger } from '../../../helpers/logger'
  9. async function sendView (byActor: ActorModel, video: VideoModel, t: Transaction) {
  10. logger.info('Creating job to send view of %s.', video.url)
  11. const activityBuilder = (audience: ActivityAudience) => {
  12. const url = getVideoLikeActivityPubUrl(byActor, video)
  13. return buildViewActivity(url, byActor, video, audience)
  14. }
  15. return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t })
  16. }
  17. function buildViewActivity (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityView {
  18. if (!audience) audience = getAudience(byActor)
  19. return audiencify(
  20. {
  21. id: url,
  22. type: 'View' as 'View',
  23. actor: byActor.url,
  24. object: video.url
  25. },
  26. audience
  27. )
  28. }
  29. // ---------------------------------------------------------------------------
  30. export {
  31. sendView
  32. }