]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/process/process-accept.ts
Add import finished and video published notifs
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-accept.ts
index e159c41b53f51a7abf7ac78b911c86b0ff3e71a3..89bda9c32a531c4d49472702e59801ccae403582 100644 (file)
@@ -1,13 +1,12 @@
-import { ActivityAccept } from '../../../../shared/models/activitypub/activity'
-import { database as db } from '../../../initializers'
-import { AccountInstance } from '../../../models/account/account-interface'
+import { ActivityAccept } from '../../../../shared/models/activitypub'
+import { ActorModel } from '../../../models/activitypub/actor'
+import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
+import { addFetchOutboxJob } from '../actor'
 
-async function processAcceptActivity (activity: ActivityAccept, inboxAccount?: AccountInstance) {
-  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 db.Account.loadByUrl(activity.actor)
-
-  return processAccept(inboxAccount, targetAccount)
+  return processAccept(inboxActor, targetActor)
 }
 
 // ---------------------------------------------------------------------------
@@ -18,10 +17,13 @@ export {
 
 // ---------------------------------------------------------------------------
 
-async function processAccept (account: AccountInstance, targetAccount: AccountInstance) {
-  const follow = await db.AccountFollow.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()
+  if (follow.state !== 'accepted') {
+    follow.set('state', 'accepted')
+    await follow.save()
+    await addFetchOutboxJob(targetActor)
+  }
 }