1 import { ActivityAccept } from '../../../../shared/models/activitypub'
2 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
3 import { addFetchOutboxJob } from '../actor'
4 import { APProcessorOptions } from '../../../types/activitypub-processor.model'
5 import { MActorDefault, MActorSignature } from '../../../types/models'
7 async function processAcceptActivity (options: APProcessorOptions<ActivityAccept>) {
8 const { byActor: targetActor, inboxActor } = options
9 if (inboxActor === undefined) throw new Error('Need to accept on explicit inbox.')
11 return processAccept(inboxActor, targetActor)
14 // ---------------------------------------------------------------------------
20 // ---------------------------------------------------------------------------
22 async function processAccept (actor: MActorDefault, targetActor: MActorSignature) {
23 const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
24 if (!follow) throw new Error('Cannot find associated follow.')
26 if (follow.state !== 'accepted') {
27 follow.state = 'accepted'
30 await addFetchOutboxJob(targetActor)