2
1

send-flag.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { ActorModel } from '../../../models/activitypub/actor'
  2. import { VideoModel } from '../../../models/video/video'
  3. import { VideoAbuseModel } from '../../../models/video/video-abuse'
  4. import { getVideoAbuseActivityPubUrl } from '../url'
  5. import { unicastTo } from './utils'
  6. import { logger } from '../../../helpers/logger'
  7. import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub'
  8. import { audiencify, getAudience } from '../audience'
  9. async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel) {
  10. if (!video.VideoChannel.Account.Actor.serverId) return // Local user
  11. const url = getVideoAbuseActivityPubUrl(videoAbuse)
  12. logger.info('Creating job to send video abuse %s.', url)
  13. // Custom audience, we only send the abuse to the origin instance
  14. const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
  15. const flagActivity = buildFlagActivity(url, byActor, videoAbuse, audience)
  16. return unicastTo(flagActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
  17. }
  18. function buildFlagActivity (url: string, byActor: ActorModel, videoAbuse: VideoAbuseModel, audience: ActivityAudience): ActivityFlag {
  19. if (!audience) audience = getAudience(byActor)
  20. const activity = Object.assign(
  21. { id: url, actor: byActor.url },
  22. videoAbuse.toActivityPubObject()
  23. )
  24. return audiencify(activity, audience)
  25. }
  26. // ---------------------------------------------------------------------------
  27. export {
  28. sendVideoAbuse
  29. }