]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/send/send-flag.ts
Add test on AP hooks
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-flag.ts
index 821637ec84b871858b2d9f72a8c6971f44abef7f..138eb5adc8d1043142bd04af816eda8428401c86 100644 (file)
@@ -1,15 +1,15 @@
 import { Transaction } from 'sequelize'
-import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub'
+import { ActivityAudience, ActivityFlag } from '@shared/models'
 import { logger } from '../../../helpers/logger'
 import { MAbuseAP, MAccountLight, MActor } from '../../../types/models'
 import { audiencify, getAudience } from '../audience'
-import { getAbuseActivityPubUrl } from '../url'
-import { unicastTo } from './utils'
+import { getLocalAbuseActivityPubUrl } from '../url'
+import { unicastTo } from './shared/send-utils'
 
 function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) {
   if (!flaggedAccount.Actor.serverId) return // Local user
 
-  const url = getAbuseActivityPubUrl(abuse)
+  const url = getLocalAbuseActivityPubUrl(abuse)
 
   logger.info('Creating job to send abuse %s.', url)
 
@@ -17,16 +17,20 @@ function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLi
   const audience = { to: [ flaggedAccount.Actor.url ], cc: [] }
   const flagActivity = buildFlagActivity(url, byActor, abuse, audience)
 
-  t.afterCommit(() => unicastTo(flagActivity, byActor, flaggedAccount.Actor.getSharedInbox()))
+  return t.afterCommit(() => {
+    return unicastTo({
+      data: flagActivity,
+      byActor,
+      toActorUrl: flaggedAccount.Actor.getSharedInbox(),
+      contextType: 'Flag'
+    })
+  })
 }
 
 function buildFlagActivity (url: string, byActor: MActor, abuse: MAbuseAP, audience: ActivityAudience): ActivityFlag {
   if (!audience) audience = getAudience(byActor)
 
-  const activity = Object.assign(
-    { id: url, actor: byActor.url },
-    abuse.toActivityPubObject()
-  )
+  const activity = { id: url, actor: byActor.url, ...abuse.toActivityPubObject() }
 
   return audiencify(activity, audience)
 }