send-dislike.ts 1.3 KB

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