]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-follow.ts
Bumped to version v1.0.0-beta.13
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-follow.ts
index 5085c5da9af690b7b90adeed282808234be5aa32..f34fd66cc24e953882dfb0d94d76391db3b3b1af 100644 (file)
@@ -11,7 +11,7 @@ async function processFollowActivity (activity: ActivityFollow) {
   const activityObject = activity.object
   const actor = await getOrCreateActorAndServerAndModel(activity.actor)
 
-  return processFollow(actor, activityObject)
+  return retryTransactionWrapper(processFollow, actor, activityObject)
 }
 
 // ---------------------------------------------------------------------------
@@ -22,16 +22,7 @@ export {
 
 // ---------------------------------------------------------------------------
 
-function processFollow (actor: ActorModel, targetActorURL: string) {
-  const options = {
-    arguments: [ actor, targetActorURL ],
-    errorMessage: 'Cannot follow with many retries.'
-  }
-
-  return retryTransactionWrapper(follow, options)
-}
-
-async function follow (actor: ActorModel, targetActorURL: string) {
+async function processFollow (actor: ActorModel, targetActorURL: string) {
   await sequelizeTypescript.transaction(async t => {
     const targetActor = await ActorModel.loadByUrl(targetActorURL, t)
 
@@ -51,6 +42,9 @@ async function follow (actor: ActorModel, targetActorURL: string) {
       transaction: t
     })
 
+    actorFollow.ActorFollower = actor
+    actorFollow.ActorFollowing = targetActor
+
     if (actorFollow.state !== 'accepted') {
       actorFollow.state = 'accepted'
       await actorFollow.save({ transaction: t })
@@ -60,7 +54,7 @@ async function follow (actor: ActorModel, targetActorURL: string) {
     actorFollow.ActorFollowing = targetActor
 
     // Target sends to actor he accepted the follow request
-    return sendAccept(actorFollow, t)
+    return sendAccept(actorFollow)
   })
 
   logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url)