aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/send/send-flag.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-15 14:52:33 +0100
committerChocobozzz <me@florianbigard.com>2019-01-15 14:59:40 +0100
commit1e7eb25f6cb6893db8f99ff40ef0509aa2a16614 (patch)
tree798937b32d894a3e1235e34398876ed875c1b72e /server/lib/activitypub/send/send-flag.ts
parent848f499def54db2dd36437ef0dfb74dd5041c23b (diff)
downloadPeerTube-1e7eb25f6cb6893db8f99ff40ef0509aa2a16614.tar.gz
PeerTube-1e7eb25f6cb6893db8f99ff40ef0509aa2a16614.tar.zst
PeerTube-1e7eb25f6cb6893db8f99ff40ef0509aa2a16614.zip
Correctly send Flag/Dislike/View activities
Diffstat (limited to 'server/lib/activitypub/send/send-flag.ts')
-rw-r--r--server/lib/activitypub/send/send-flag.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/server/lib/activitypub/send/send-flag.ts b/server/lib/activitypub/send/send-flag.ts
new file mode 100644
index 000000000..96a7311b9
--- /dev/null
+++ b/server/lib/activitypub/send/send-flag.ts
@@ -0,0 +1,39 @@
1import { ActorModel } from '../../../models/activitypub/actor'
2import { VideoModel } from '../../../models/video/video'
3import { VideoAbuseModel } from '../../../models/video/video-abuse'
4import { getVideoAbuseActivityPubUrl } from '../url'
5import { unicastTo } from './utils'
6import { logger } from '../../../helpers/logger'
7import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub'
8import { audiencify, getAudience } from '../audience'
9
10async 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
24function 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
37export {
38 sendVideoAbuse
39}