]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-accept.ts
Merge branch 'release/v1.2.0'
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-accept.ts
index 5b321f771d348aa4d3c9727c036769b209972ba1..ebb275e348fe840cff7782dd976a8edc314ab4c0 100644 (file)
@@ -1,14 +1,12 @@
 import { ActivityAccept } from '../../../../shared/models/activitypub'
-import { AccountModel } from '../../../models/account/account'
-import { AccountFollowModel } from '../../../models/account/account-follow'
-import { addFetchOutboxJob } from '../fetch'
+import { ActorModel } from '../../../models/activitypub/actor'
+import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
+import { addFetchOutboxJob } from '../actor'
 
-async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountModel) {
-  if (inboxAccount === undefined) throw new Error('Need to accept on explicit inbox.')
+async function processAcceptActivity (activity: ActivityAccept, targetActor: ActorModel, inboxActor?: ActorModel) {
+  if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
 
-  const targetAccount = await AccountModel.loadByUrl(activity.actor)
-
-  return processAccept(inboxAccount, targetAccount)
+  return processAccept(inboxActor, targetActor)
 }
 
 // ---------------------------------------------------------------------------
@@ -19,11 +17,14 @@ export {
 
 // ---------------------------------------------------------------------------
 
-async function processAccept (account: AccountModel, targetAccount: AccountModel) {
-  const follow = await AccountFollowModel.loadByAccountAndTarget(account.id, targetAccount.id)
+async function processAccept (actor: ActorModel, targetActor: ActorModel) {
+  const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
   if (!follow) throw new Error('Cannot find associated follow.')
 
-  follow.set('state', 'accepted')
-  await follow.save()
-  await addFetchOutboxJob(targetAccount, undefined)
+  if (follow.state !== 'accepted') {
+    follow.set('state', 'accepted')
+    await follow.save()
+
+    await addFetchOutboxJob(targetActor)
+  }
 }