]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/send/send-flag.ts
Merge branch 'develop' into pr/1217
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-flag.ts
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
10 async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel) {
11 if (!video.VideoChannel.Account.Actor.serverId) return // Local user
12
13 const url = getVideoAbuseActivityPubUrl(videoAbuse)
14
15 logger.info('Creating job to send video abuse %s.', url)
16
17 // Custom audience, we only send the abuse to the origin instance
18 const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
19 const flagActivity = buildFlagActivity(url, byActor, videoAbuse, audience)
20
21 return unicastTo(flagActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
22 }
23
24 function buildFlagActivity (url: string, byActor: ActorModel, videoAbuse: VideoAbuseModel, audience: ActivityAudience): ActivityFlag {
25 if (!audience) audience = getAudience(byActor)
26
27 const activity = Object.assign(
28 { id: url, actor: byActor.url },
29 videoAbuse.toActivityPubObject()
30 )
31
32 return audiencify(activity, audience)
33 }
34
35 // ---------------------------------------------------------------------------
36
37 export {
38 sendVideoAbuse
39 }