send-like.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Transaction } from 'sequelize'
  2. import { ActivityAudience, ActivityLike } 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 sendLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
  10. logger.info('Creating job to like %s.', video.url)
  11. const activityBuilder = (audience: ActivityAudience) => {
  12. const url = getVideoLikeActivityPubUrl(byActor, video)
  13. return buildLikeActivity(url, byActor, video, audience)
  14. }
  15. return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t })
  16. }
  17. function buildLikeActivity (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityLike {
  18. if (!audience) audience = getAudience(byActor)
  19. return audiencify(
  20. {
  21. id: url,
  22. type: 'Like' as 'Like',
  23. actor: byActor.url,
  24. object: video.url
  25. },
  26. audience
  27. )
  28. }
  29. // ---------------------------------------------------------------------------
  30. export {
  31. sendLike,
  32. buildLikeActivity
  33. }