]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/send/send-accept.ts
Add ability to search a video with an URL
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-accept.ts
index 7579884a79ca43f241a5d325e9bfda903f1918e9..ef679707bfe72df3d9332f531e8ee6691da53d2a 100644 (file)
@@ -1,18 +1,29 @@
-import { Transaction } from 'sequelize'
-import { ActivityAccept } from '../../../../shared/models/activitypub'
+import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub'
 import { ActorModel } from '../../../models/activitypub/actor'
 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
-import { getActorFollowAcceptActivityPubUrl } from '../url'
-import { unicastTo } from './misc'
+import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
+import { unicastTo } from './utils'
+import { followActivityData } from './send-follow'
+import { logger } from '../../../helpers/logger'
 
-async function sendAccept (actorFollow: ActorFollowModel, t: Transaction) {
+async function sendAccept (actorFollow: ActorFollowModel) {
   const follower = actorFollow.ActorFollower
   const me = actorFollow.ActorFollowing
 
+  if (!follower.serverId) { // This should never happen
+    logger.warn('Do not sending accept to local follower.')
+    return
+  }
+
+  logger.info('Creating job to accept follower %s.', follower.url)
+
+  const followUrl = getActorFollowActivityPubUrl(actorFollow)
+  const followData = followActivityData(followUrl, follower, me)
+
   const url = getActorFollowAcceptActivityPubUrl(actorFollow)
-  const data = acceptActivityData(url, me)
+  const data = acceptActivityData(url, me, followData)
 
-  return unicastTo(data, me, follower.inboxUrl, t)
+  return unicastTo(data, me, follower.inboxUrl)
 }
 
 // ---------------------------------------------------------------------------
@@ -23,10 +34,11 @@ export {
 
 // ---------------------------------------------------------------------------
 
-function acceptActivityData (url: string, byActor: ActorModel): ActivityAccept {
+function acceptActivityData (url: string, byActor: ActorModel, followActivityData: ActivityFollow): ActivityAccept {
   return {
     type: 'Accept',
     id: url,
-    actor: byActor.url
+    actor: byActor.url,
+    object: followActivityData
   }
 }